summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-stdio-inherit.js
blob: d2b64aeb30dd31fe25ea117b5c47e9013678a862 (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
'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;

if (process.argv[2] === 'parent')
  parent();
else
  grandparent();

function grandparent() {
  const child = spawn(process.execPath, [__filename, 'parent']);
  child.stderr.pipe(process.stderr);
  let output = '';
  const input = 'asdfasdf';

  child.stdout.on('data', function(chunk) {
    output += chunk;
  });
  child.stdout.setEncoding('utf8');

  child.stdin.end(input);

  child.on('close', function(code, signal) {
    assert.strictEqual(code, 0);
    assert.strictEqual(signal, null);
    // cat on windows adds a \r\n at the end.
    assert.strictEqual(output.trim(), input.trim());
  });
}

function parent() {
  // should not immediately exit.
  common.spawnCat({ stdio: 'inherit' });
}