Go实例: Exec'ing Processes

Fiorenza ·
更新时间:2024-11-10
· 91 次阅读

package main import ( "os" "os/exec" "syscall" ) func main() { binary, lookErr := exec.LookPath("ls") if lookErr != nil { panic(lookErr) } args := []string{"ls", "-a", "-l", "-h"} env := os.Environ() execErr := syscall.Exec(binary, args, env) if execErr != nil { panic(execErr) } }$ go run execing-processes.go total 16 drwxr-xr-x 4 mark 136B Oct 3 16:29 . drwxr-xr-x 91 mark 3.0K Oct 3 12:50 .. -rw-r--r-- 1 mark 1.3K Oct 3 16:28 execing-processes.go



GO实例 exec GO

需要 登录 后方可回复, 如果你还没有账号请 注册新账号