dtzd65908 2015-07-02 03:03
浏览 24
已采纳

exec.Command不会从Go的pprof工具中注册错误

Here is my code:

cmd := exec.Command("go", "tool", "pprof", "-dot", "-lines", "http://google.com")
out, err := cmd.Output()
if err != nil {
    panic(err)
}
println(string(out))

When I run the exact same command in my console, I see:

$ go tool pprof -dot -lines http://google.com 
Fetching profile from http://google.com/profilez
Please wait... (30s)
server response: 404 Not Found 

However, my go program does not register that this is an error. Oddly, the variable out prints as an empty string and err is nil. What is going on?

To clarify, I am profiling http://google.com to purposefully create an error. I would normally profile a real Go application.

  • 写回答

1条回答 默认 最新

  • donglao4370 2015-07-02 03:13
    关注

    The text

    Fetching profile from http://google.com/profilez
    Please wait... (30s)
    server response: 404 Not Found 
    

    is written to stderr. Your program captures stdout, which is empty. Consider calling:

    out, err := cmd.CombinedOutput()
    

    to grab both stdout and stderr.

    cmd.Output() and cmd.CombinedOutput() return err == nil because the command exits with status zero. Perhaps an issue should be filed requesting that the command exit with non-zero status.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口