cmd := exec.Command("cmd")
in := bytes.NewBuffer(nil)
cmd.Stdin = in//绑定输入
var out bytes.Buffer
cmd.Stdout = &out //绑定输出
go func() {
in.WriteString("node E:/design/test.js\n")//写入你的命令,可以有多行,"\n"表示回车
}()
err = cmd.Start()
if err != nil {
log.Fatal(err)
}
log.Println(cmd.Args)
err = cmd.Wait()
if err != nil {
log.Printf("Command finished with error: %v", err)
}
fmt.Println(out.String())
golang执行命令 exec.Command
最新推荐文章于 2024-08-14 18:24:06 发布