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 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题