27 lines
449 B
Go
27 lines
449 B
Go
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")
|
|
}
|