node 父进程捕获子进程错误信息


childProcess.on()childProcess.stderr.on() 的区别

  • childProcess.on('error', err =>{}) 用于捕获名为 error 的事件(event)(用try-catch是没用的)
  • childProcess.stderr.on('error', err =>{}) 用于捕获所有输出到标准错误流中的信息
  • 在子进程的异常处理中,把异常信息打印到stderr,比如在python中:print("exception details", file=sys.stderr)

参考

  • https://node.readthedocs.io/en/stable/api/child_process/
  • https://stackoverflow.com/questions/34208614/how-to-catch-an-enoent-with-nodejs-child-process-spawn
  • https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python