Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
SIGPIPE on stdout should kill the process by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Apr 22, 2010
1 parent 3934cb5 commit d70474d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/node.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ process.__defineGetter__('stdout', function () {
if (stdout) return stdout; if (stdout) return stdout;
var net = module.requireNative('net'); var net = module.requireNative('net');
stdout = new net.Stream(process.binding('stdio').stdoutFD); stdout = new net.Stream(process.binding('stdio').stdoutFD);

stdout.addListener('error', function (err) { throw err; });

return stdout; return stdout;
}); });


Expand All @@ -140,6 +143,7 @@ process.openStdin = function () {
var net = module.requireNative('net'); var net = module.requireNative('net');
var fd = process.binding('stdio').openStdin(); var fd = process.binding('stdio').openStdin();
stdin = new net.Stream(fd); stdin = new net.Stream(fd);
stdin.addListener('error', function (err) { throw err; });
stdin.resume(); stdin.resume();
stdin.readable = true; stdin.readable = true;
return stdin; return stdin;
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/print-10-lines.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,4 @@
puts = require('sys').puts;
for (var i = 0; i < 10; i++) {
puts('count ' + i);
}
23 changes: 23 additions & 0 deletions test/simple/test-pipe-head.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,23 @@
require('../common');

exec = require('child_process').exec;
join = require('path').join;

nodePath = process.argv[0];
script = join(fixturesDir, 'print-10-lines.js');

cmd = nodePath + ' ' + script + ' | head -2';

finished = false;

exec(cmd, function (err, stdout, stderr) {
if (err) throw err;
lines = stdout.split('\n');
assert.equal(3, lines.length);
finished = true;
});


process.addListener('exit', function () {
assert.ok(finished);
});

0 comments on commit d70474d

Please sign in to comment.