how to get log info when i run cmd.start(xx.exe)

Viewed 31

source code is:

//this code run in parent process
cmd:=exec.Command("cmd","/c","./child.exe")
if e:=cmd.Start();e!=nil{
  //todo handle error
}
//child.exe handle task maybe long time
os.Exit() //notice!!! parent process will kill itself because test.exe will rm parent process

My problem is test.exe have anything log info in cmd.

1 Answers

More or less like this:

cmd := exec.Command("cmd", "/c", "./child.exe")
out := bytes.NewBuffer(nil)
cmd.Stdout = out
if err := cmd.Run(); err != nil {

}
fmt.Println(out.String())
Related