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 process.stdin; 11 process.stdout; 12 process.stderr; 13 return; 14 } 15 const python = process.env.PYTHON || 'python'; 16 const script = fixtures.path('spawn_closed_stdio.py'); 17 const proc = spawn(python, [script, process.execPath, __filename, 'child']); 18 proc.on('exit', common.mustCall(function(exitCode) { 19 assert.strictEqual(exitCode, 0); 20 })); 21 return; 22} 23 24if (process.argv[2] === 'child') { 25 [0, 1, 2].forEach((i) => fs.fstatSync(i)); 26 return; 27} 28 29// Run the script in a shell but close stdout and stderr. 30const cmd = `"${process.execPath}" "${__filename}" child 1>&- 2>&-`; 31const proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit' }); 32 33proc.on('exit', common.mustCall(function(exitCode) { 34 assert.strictEqual(exitCode, 0); 35})); 36