gobyexample/exec/exec.go

27 lines
449 B
Go
Raw Normal View History

2024-05-04 18:32:38 +00:00
package exec
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func Exec() {
defer fmt.Println("defer println")
lsPath, err := exec.LookPath("ls")
if err != nil {
panic(err)
}
envs := os.Environ()
// Exec replaces currently running go program and doesn't seem to care for `defer`s either
execErr := syscall.Exec(lsPath, []string{"-l", "-a", "-h", "/"}, envs)
if execErr != nil {
panic(execErr)
}
fmt.Println("Stopping the program")
}