Golang运行系统命令

# https://github.com/go-cmd/cmd
# 示例代码
func runCommand() {
	// Create Cmd, buffered output
	envCmd := cmd.NewCmd("./testmain.exe")

	// Run and wait for Cmd to return Status
	status := envCmd.Start()
	// envCmd.Stop()
	finalStatus := <-status
	fmt.Println(finalStatus.Stdout)

	// Print each line of STDOUT from Cmd
	// for _, line := range status.Stdout {
	// 	fmt.Println(line)
	// }
}
posted @ 2020-06-24 00:10  ruixing  阅读(1388)  评论(0编辑  收藏  举报