Files
llgo/_cmptest/osproc/exec.go

31 lines
479 B
Go
Raw Normal View History

2024-07-18 14:30:49 +08:00
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
)
func main() {
ls := "ls"
args := []string{ls, "-l"}
if runtime.GOOS == "windows" {
ls = "dir"
args = []string{ls}
}
lspath, _ := exec.LookPath(ls)
if lspath != "" {
ls = lspath
}
proc, err := os.StartProcess(ls, args, &os.ProcAttr{
Files: []*os.File{nil, os.Stdout, os.Stderr},
})
if err != nil {
fmt.Println("os.StartProcess error:", err)
return
}
proc.Wait()
2024-07-18 22:27:00 +08:00
fmt.Println("proc.Wait done")
2024-07-18 14:30:49 +08:00
}