node.js API 文档在生成子进程时使用额外的 stdio (fd=4):
// Open an extra fd=4, to interact with programs present a
// startd-style interface.
spawn('prg', [], { stdio: ['pipe', null, null, null, 'pipe'] });
该 stdio 将可通过ChildProcess.stdio[fd]
.
子进程如何访问这些额外的 stdio?让我们在文件描述符 3 (fd=3) 上使用流而不是管道。
/* parent process */
// open file for read/write
var mStream = fs.openSync('./shared-stream', 'r+');
// spawn child process with stream object as fd=3
spawn('node', ['/path/to/child.js'], {stdio: [0, 1, 2, mStream] });