diff options
author | Tyler Neylon <tylerneylon@gmail.com> | 2012-08-03 12:38:09 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-08-04 11:30:58 -0700 |
commit | b48684c6f1958930741e2cf34a6a6d5cafa7f478 (patch) | |
tree | e3ad8daa0ea3ab37573dad5f444c8494ff7c1fdb /lib | |
parent | a7f3288a87c563f0910f17cbed503574b6ceea54 (diff) | |
download | node-new-b48684c6f1958930741e2cf34a6a6d5cafa7f478.tar.gz |
child_process: Fix stdout=null when stdio=['pipe']
Previously, a command with a short stdio array would result in the child's
stdout and stderr objects set to null. For example:
var c = child_process.spawn(cmd, args, {stdio: ['pipe']});
// results in c.stdout === null.
The expected behavior is the above line functioning the same as this one:
var c = child_process.spawn(cmd, args, {stdio: ['pipe', null, null]});
// provides correct (non-null) c.stdout; as does the above, after this fix.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/child_process.js | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/child_process.js b/lib/child_process.js index 34edbc25ad..5b0c3f318b 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -709,9 +709,10 @@ ChildProcess.prototype.spawn = function(options) { } // At least 3 stdio will be created - if (stdio.length < 3) { - stdio = stdio.concat(new Array(3 - stdio.length)); - } + // Don't concat() a new Array() because it would be sparse, and + // stdio.reduce() would skip the sparse elements of stdio. + // See http://stackoverflow.com/a/5501711/3561 + while (stdio.length < 3) stdio.push(undefined); // Translate stdio into C++-readable form // (i.e. PipeWraps or fds) |