Spawning processes
Context
Section titled “Context”The os/exec package spawns external processes. You can run commands and capture their output.
Example
Section titled “Example”Run ls -l and print the output.
Code example
Section titled “Code example”package main
import ( "fmt" "os/exec")
func main() { cmd := exec.Command("ls", "-l") out, err := cmd.Output() if err != nil { fmt.Println("Error:", err) return } fmt.Println(string(out))}Output (example)
Section titled “Output (example)”total 0-rw-r--r-- 1 user staff 0 Jan 1 12:00 file.txt