Files
llgo/_demo/go/sysexec/exec.go

27 lines
367 B
Go
Raw Normal View History

2024-07-12 00:39:16 +08:00
package main
import (
"fmt"
"os/exec"
"runtime"
"syscall"
)
func main() {
ls := "ls"
args := []string{ls, "-l"}
2024-07-12 00:39:16 +08:00
if runtime.GOOS == "windows" {
ls = "dir"
args = []string{ls}
2024-07-12 00:39:16 +08:00
}
lspath, _ := exec.LookPath(ls)
if lspath != "" {
ls = lspath
}
err := syscall.Exec(ls, args, nil)
if err != nil {
fmt.Println("syscall.Exec error:", err)
return
}
}