golangをwindowsにインストールしているのですがsyscallを利用するとコンパイル時にエラーが出てしまい、使用できません。golangはwindowsでsyscallは使用できないのでしょうか。
コードは以下になります。
go
1package main 2 3import ( 4 "fmt" 5 "log" 6 "os" 7 "os/exec" 8 "syscall" 9) 10 11func main() { 12 cpath, err := exec.LookPath(os.Args[1]) 13 if err != nil { 14 log.Fatalf("%s not found in $PATH.", os.Args[1]) 15 } 16 args := os.Args[1:] 17 attr :=syscall.ProcAttr{Files: []uintptr{0, 1, 2}} 18 pid, err :=syscall.forkExec(cpath, args, &attr) 19 if err != nil { 20 panic(err) 21 } 22 proc, err := os.findProcess(pid) 23 status, err := proc.Wait() 24 if err != nil { 25 panic(err) 26 } 27 if !status.Succcess() { 28 fmt.Println(status.String()) 29 } 30} 31
エラーは以下です
.\test.go:18:13: cannot refer to unexported name syscall.forkExec
.\test.go:18:13: undefined: syscall.forkExec
.\test.go:22:15: cannot refer to unexported name os.findProcess
.\test.go:22:15: undefined: os.findProcess
あなたの回答
tips
プレビュー