diff options
author | Javis Sullivan <javissullivan@gmail.com> | 2017-01-18 02:22:37 -0500 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2017-01-27 12:06:48 -0800 |
commit | 3268863ebc40d1f0beee61b044c492b43fa57fa5 (patch) | |
tree | 68c5f5323cc0bcb78f4603463ec946e936224849 /lib/child_process.js | |
parent | b6d2fc9b0f6a896462fe3e78cf95e48ecef59053 (diff) | |
download | android-node-v8-3268863ebc40d1f0beee61b044c492b43fa57fa5.tar.gz android-node-v8-3268863ebc40d1f0beee61b044c492b43fa57fa5.tar.bz2 android-node-v8-3268863ebc40d1f0beee61b044c492b43fa57fa5.zip |
child_process: add string shortcut for fork stdio
Add string shortcut option for stdio parameter.
Fixes: https://github.com/nodejs/node/issues/10793
PR-URL: https://github.com/nodejs/node/pull/10866
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'lib/child_process.js')
-rw-r--r-- | lib/child_process.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/child_process.js b/lib/child_process.js index e9cf426b9e..b00e3829b4 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -17,6 +17,10 @@ const _validateStdio = child_process._validateStdio; const setupChannel = child_process.setupChannel; const ChildProcess = exports.ChildProcess = child_process.ChildProcess; +function stdioStringToArray(option) { + return [option, option, option, 'ipc']; +} + exports.fork = function(modulePath /*, args, options*/) { // Get options and args arguments. @@ -50,11 +54,21 @@ exports.fork = function(modulePath /*, args, options*/) { args = execArgv.concat([modulePath], args); - if (!Array.isArray(options.stdio)) { + if (typeof options.stdio === 'string') { + switch (options.stdio) { + case 'ignore': + case 'pipe': + case 'inherit': + options.stdio = stdioStringToArray(options.stdio); + break; + default: + throw new TypeError('Unknown stdio option'); + } + } else if (!Array.isArray(options.stdio)) { // Use a separate fd=3 for the IPC channel. Inherit stdin, stdout, // and stderr from the parent if silent isn't set. - options.stdio = options.silent ? ['pipe', 'pipe', 'pipe', 'ipc'] : - [0, 1, 2, 'ipc']; + options.stdio = options.silent ? stdioStringToArray('pipe') : + stdioStringToArray('inherit'); } else if (options.stdio.indexOf('ipc') === -1) { throw new TypeError('Forked processes must have an IPC channel'); } |