0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/simple/test-child-process-stdin.js
Ryan Dahl ba792ea202 :%s/sys.puts/console.log/g
and there was much rejoicing
2010-06-23 20:05:29 -07:00

49 lines
945 B
JavaScript

require("../common");
var spawn = require('child_process').spawn;
var cat = spawn("cat");
cat.stdin.write("hello");
cat.stdin.write(" ");
cat.stdin.write("world");
cat.stdin.end();
var response = "";
var exitStatus = -1;
var gotStdoutEOF = false;
cat.stdout.setEncoding('utf8');
cat.stdout.addListener("data", function (chunk) {
console.log("stdout: " + chunk);
response += chunk;
});
cat.stdout.addListener('end', function () {
gotStdoutEOF = true;
});
var gotStderrEOF = false;
cat.stderr.addListener("data", function (chunk) {
// shouldn't get any stderr output
assert.ok(false);
});
cat.stderr.addListener("end", function (chunk) {
gotStderrEOF = true;
});
cat.addListener("exit", function (status) {
console.log("exit event");
exitStatus = status;
assert.equal("hello world", response);
});
process.addListener("exit", function () {
assert.equal(0, exitStatus);
assert.equal("hello world", response);
});