• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const spawn = require('child_process').spawn;
5const fs = require('fs');
6const fixtures = require('../common/fixtures');
7
8if (common.isWindows) {
9  if (process.argv[2] === 'child') {
10    /* eslint-disable no-unused-expressions */
11    process.stdin;
12    process.stdout;
13    process.stderr;
14    return;
15    /* eslint-enable no-unused-expressions */
16  }
17  const python = process.env.PYTHON || 'python';
18  const script = fixtures.path('spawn_closed_stdio.py');
19  const proc = spawn(python, [script, process.execPath, __filename, 'child']);
20  proc.on('exit', common.mustCall(function(exitCode) {
21    assert.strictEqual(exitCode, 0);
22  }));
23  return;
24}
25
26if (process.argv[2] === 'child') {
27  [0, 1, 2].forEach((i) => fs.fstatSync(i));
28  return;
29}
30
31// Run the script in a shell but close stdout and stderr.
32const cmd = `"${process.execPath}" "${__filename}" child 1>&- 2>&-`;
33const proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit' });
34
35proc.on('exit', common.mustCall(function(exitCode) {
36  assert.strictEqual(exitCode, 0);
37}));
38