Skip to content
This repository has been archived by the owner on May 14, 2018. It is now read-only.

Fix usage with stdio 'ignore'. #26

Merged
merged 1 commit into from
Jul 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ var options = (args[2] && typeof args[2] === 'object') ?

var complete = false;
var stdout, stderr;
child.stdout.pipe(concat(function (buf) {
child.stdout && child.stdout.pipe(concat(function (buf) {
stdout = buf.length ? buf : new Buffer(0);
}));
child.stderr.pipe(concat(function (buf) {
child.stderr && child.stderr.pipe(concat(function (buf) {
stderr = buf.length ? buf : new Buffer(0);
}));
child.on('error', function (err) {
Expand Down
19 changes: 19 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ function testSpawn(spawn) {
assert(result.stdout.toString() === '');
assert(result.stderr.toString() === '');

var result = spawn("node", [__dirname + '/test-empty.js'], { stdio: ['pipe', 'ignore', 'pipe']});
assert(result.status === 0);
assert(Buffer.isBuffer(result.stderr));
assert(result.stdout == null);
assert(result.stderr.toString() === '');

var result = spawn("node", [__dirname + '/test-empty.js'], { stdio: ['pipe', 'pipe', 'ignore']});
assert(result.status === 0);
assert(Buffer.isBuffer(result.stdout));
assert(result.stdout.toString() === '');
assert(result.stderr == null);

var result = spawn("node", [__dirname + '/test-empty.js'], { stdio: ['ignore', 'pipe', 'pipe']});
assert(result.status === 0);
assert(Buffer.isBuffer(result.stdout));
assert(Buffer.isBuffer(result.stderr));
assert(result.stdout.toString() === '');
assert(result.stderr.toString() === '');

// This suprisingly fails for the official API
/*
var start = Date.now();
Expand Down