node.js - Accessing the exit code and stderr of a system command

前端 未结 3 985
春和景丽
春和景丽 2020-12-14 00:43

The code snippet shown below works great for obtaining access to the stdout of a system command. Is there some way that I can modify this code so as to also get access to t

3条回答
  •  無奈伤痛
    2020-12-14 00:55

    You may also use child_process.spawnSync(), as it returns much more:

    return: 
    pid  Pid of the child process
    output  Array of results from stdio output
    stdout  |  The contents of output[1]
    stderr  |  The contents of output[2]
    status  The exit code of the child process
    signal  The signal used to kill the child process
    error  The error object if the child process failed or timed out
    

    So the exit code you're looking for would be ret.status.

提交回复
热议问题