summaryrefslogtreecommitdiff
path: root/test/simple/test-child-process-stdin.js
blob: 730ae5ca1b7d64ec798747875e214aecccf76fc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
});