child_process: support stdio option in fork() · nodejs/node@da481c6 · GitHub
Skip to content

Commit da481c6

Browse files
committed
child_process: support stdio option in fork()
This commit allows child_process.fork() to pass stdio options to spawn(). This allows fork() to more easily take advantage of additional stdio channels. Refs: nodejs/node-v0.x-archive#5727 PR-URL: #7811 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
1 parent 2f45941 commit da481c6

3 files changed

Lines changed: 64 additions & 4 deletions

File tree

doc/api/child_process.md

Lines changed: 2 additions & 0 deletions

lib/child_process.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ exports.fork = function(modulePath /*, args, options*/) {
4444

4545
args = execArgv.concat([modulePath], args);
4646

47-
// Leave stdin open for the IPC channel. stdout and stderr should be the
48-
// same as the parent's if silent isn't set.
49-
options.stdio = options.silent ? ['pipe', 'pipe', 'pipe', 'ipc'] :
50-
[0, 1, 2, 'ipc'];
47+
if (!Array.isArray(options.stdio)) {
48+
// Leave stdin open for the IPC channel. stdout and stderr should be the
49+
// same as the parent's if silent isn't set.
50+
options.stdio = options.silent ? ['pipe', 'pipe', 'pipe', 'ipc'] :
51+
[0, 1, 2, 'ipc'];
52+
} else if (options.stdio.indexOf('ipc') === -1) {
53+
throw new TypeError('Forked processes must have an IPC channel');
54+
}
5155

5256
options.execPath = options.execPath || process.execPath;
5357

Lines changed: 54 additions & 0 deletions

0 commit comments

Comments
 (0)