在 NodeJs 中使用 child_process.execSync 进行错误处理

2 stdout stderr child-process node.js

这是我的 NodeJs 片段:

const {execSync} = require('child_process');
  testoutput = execSync('make test');
Run Code Online (Sandbox Code Playgroud)

如果 make 进程完全退出,我将从execSync 进程获取stdout作为testoutput变量的输出。但是,如果make 测试过程遇到stderr错误,那么我会在 NodeJs 中收到错误。

如果 make 进程不退出,如何将stderr消息存储到输出变量testoutput;如果进程以stdout 输出正常退出,则如何将stdout存储到变量testoutput中。