Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
exec.命令未从Go';我们自己的工具_Go_Pprof - Fatal编程技术网

exec.命令未从Go';我们自己的工具

exec.命令未从Go';我们自己的工具,go,pprof,Go,Pprof,这是我的密码: cmd := exec.Command("go", "tool", "pprof", "-dot", "-lines", "http://google.com") out, err := cmd.Output() if err != nil { panic(err) } println(string(out)) 当我在控制台中运行完全相同的命令时,我看到: $ go tool pprof -dot -lines http://google.com Fetching p

这是我的密码:

cmd := exec.Command("go", "tool", "pprof", "-dot", "-lines", "http://google.com")
out, err := cmd.Output()
if err != nil {
    panic(err)
}
println(string(out))
当我在控制台中运行完全相同的命令时,我看到:

$ go tool pprof -dot -lines http://google.com 
Fetching profile from http://google.com/profilez
Please wait... (30s)
server response: 404 Not Found 
但是,我的go程序没有记录这是一个错误。奇怪的是,变量out打印为空字符串,err为nil。发生了什么事

为了澄清这一点,我正在分析有目的地创建一个错误。我通常会分析一个真正的Go应用程序。

文本

Fetching profile from http://google.com/profilez
Please wait... (30s)
server response: 404 Not Found 
是写给stderr的。您的程序捕获空的stdout。考虑调用:

out, err := cmd.CombinedOutput()
要同时抓取stdout和stderr

cmd.Output()
cmd.CombinedOutput()
返回
err==nil
,因为命令退出时状态为零。也许应该提交一个问题,请求命令以非零状态退出