duanpiangeng8958 2018-02-11 11:34
浏览 758

执行nodejs并获得错误输出

I am trying to fire a command via exec in my go binary to get JSON output of the other script. The other script is a nodejs task checking for html problems. If I fire the nodeJS task on cli everything works fine and I get JSON output, but if I fire the command inside of go I only get:

exit status 1

I am not total sure if the problem is a nodejs or a go problem, but even if nodejs founds HTML Problems I want to be able to analyze the JSON Response in my go script.

Here is my source code:

out, err := exec.Command("/usr/bin/testcafe", "'chromium:headless --no-sandbox'", "--reporter json", "/data/checks.js").Output()
status := http.StatusOK
message := ""
if err != nil {
    status = http.StatusNotImplemented
    message = err.Error() + string(string(out[:]))
    fmt.Println(message)
}
  • 写回答

2条回答 默认 最新

  • dongliao3742 2018-02-11 16:26
    关注

    As mentioned above if you ever need to access Stderr from an Command Exit in Golang use:

    message += string(err.(*exec.ExitError).Stderr[:])
    

    In my case the nodejs tool gave an exit code based on the amounts of problems. Solved this it runs perfectly now =).

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程