首页 > 解决方案 > NodeJS:产生子进程,并捕获孙进程的标准输出?

问题描述

我正在尝试使用 NodeJS 启动一个进程child_process,并且该进程本身会产生另一个进程。我正在尝试捕获孙进程标准输出或检测它正在关闭。出现了几个问题。

  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'
});

如何查看子进程产生的子进程,并检测它何时关闭或退出?

标签: javascriptnode.jschild-processsteam

解决方案


推荐阅读