我就废话不多说了,大家还是直接看代码吧~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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()) |