Exec'ing Processes
package main
import (
"os"
"os/exec"
"syscall"
)
func main() {
// LookPath searches for the ls binary in the PATH environment variable.
binary, lookErr := exec.LookPath("ls")
if lookErr != nil {
panic(lookErr)
}
// Command-line arguments for the ls command.
args := []string{"ls", "-a", "-l", "-h"}
// Get the current environment variables.
env := os.Environ()
// Replace the current process with the ls command.
execErr := syscall.Exec(binary, args, env)
if execErr != nil {
panic(execErr)
}
}Last updated