NodeJS:生成子进程,并捕获子进程的标准输出?

时间:2020-04-12 16:01:58

标签: javascript node.js child-process steam

我正在尝试使用NodeJS child_process启动一个进程,该进程本身产生了另一个进程。我正在尝试捕获孙子进程stdout或检测到它关闭。出现了一些问题。

  1. 我的程序不知道可执行文件的文件名。 (无法使用任务列表)
  2. 启动孙子进程后,子进程立即关闭。
const spawn = require('child_process').spawn;

let childProcess = spawn('pathToExe', ['exeArgs'], {stdio: 'pipe'});
childProcess.stdout.on('data', (data) => {
  // Here I can capture the child process STDOUT
  // The child process closes instantly after spawning the 'grandchild'
});

我如何查看子进程产生了哪些子进程,并检测其何时关闭或退出?

0 个答案:

没有答案
相关问题