@@ -17,6 +17,10 @@ const _validateStdio = child_process._validateStdio;
1717const setupChannel = child_process . setupChannel ;
1818const ChildProcess = exports . ChildProcess = child_process . ChildProcess ;
1919
20+ function stdioStringToArray ( option ) {
21+ return [ option , option , option , 'ipc' ] ;
22+ }
23+
2024exports . fork = function ( modulePath /*, args, options*/ ) {
2125
2226 // Get options and args arguments.
@@ -50,11 +54,21 @@ exports.fork = function(modulePath /*, args, options*/) {
5054
5155 args = execArgv . concat ( [ modulePath ] , args ) ;
5256
53- if ( ! Array . isArray ( options . stdio ) ) {
57+ if ( typeof options . stdio === 'string' ) {
58+ switch ( options . stdio ) {
59+ case 'ignore' :
60+ case 'pipe' :
61+ case 'inherit' :
62+ options . stdio = stdioStringToArray ( options . stdio ) ;
63+ break ;
64+ default :
65+ throw new TypeError ( 'Unknown stdio option' ) ;
66+ }
67+ } else if ( ! Array . isArray ( options . stdio ) ) {
5468 // Use a separate fd=3 for the IPC channel. Inherit stdin, stdout,
5569 // and stderr from the parent if silent isn't set.
56- options . stdio = options . silent ? [ 'pipe' , 'pipe' , 'pipe' , 'ipc' ] :
57- [ 0 , 1 , 2 , 'ipc' ] ;
70+ options . stdio = options . silent ? stdioStringToArray ( 'pipe' ) :
71+ stdioStringToArray ( 'inherit' ) ;
5872 } else if ( options . stdio . indexOf ( 'ipc' ) === - 1 ) {
5973 throw new TypeError ( 'Forked processes must have an IPC channel' ) ;
6074 }
0 commit comments