//调用exe
func callEXE1() { arg := []string{} cmd := exec.Command("test", arg...) //会向 cmd.Stdout和cmd.Stderr写入信息,其实cmd.Stdout==cmd.Stderr,具体可见源码 output, err := cmd.CombinedOutput() if err != nil { fmt.Println("Error:", err) return } fmt.Printf("callEXE2结果:\n%v\n\n%v\n\n%v", string(output), cmd.Stdout, cmd.Stderr) } func callEXE2() { arg := []string{} cmd := exec.Command("test", arg...) //会向 cmd.Stdout写入信息 output, err := cmd.Output() if err != nil { fmt.Printf("Error: %s\n", err) return } fmt.Printf("callEXE2结果:\n%v\n%v\n%v", string(output), cmd.Stdout, cmd.Stderr) }
test.exe源码:
//vs 2010 c++ #include "stdafx.h" #include<iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { std::cout<<"中国,zhongguo2014"<<endl; //std::cerr<<"中国,zhongguo2014"<<endl; //std::clog<<"中国,zhongguo2014"<<endl; fprintf(stderr,"中国,zhongguo2013"); //fprintf(stdout,"中国,zhongguo2013"); return 0; }
有疑问加站长微信联系(非本文作者)