11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst spawn = require('child_process').spawn;
51cb0ef41Sopenharmony_ciconst fs = require('fs');
61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciif (common.isWindows) {
91cb0ef41Sopenharmony_ci  if (process.argv[2] === 'child') {
101cb0ef41Sopenharmony_ci    /* eslint-disable no-unused-expressions */
111cb0ef41Sopenharmony_ci    process.stdin;
121cb0ef41Sopenharmony_ci    process.stdout;
131cb0ef41Sopenharmony_ci    process.stderr;
141cb0ef41Sopenharmony_ci    return;
151cb0ef41Sopenharmony_ci    /* eslint-enable no-unused-expressions */
161cb0ef41Sopenharmony_ci  }
171cb0ef41Sopenharmony_ci  const python = process.env.PYTHON || 'python';
181cb0ef41Sopenharmony_ci  const script = fixtures.path('spawn_closed_stdio.py');
191cb0ef41Sopenharmony_ci  const proc = spawn(python, [script, process.execPath, __filename, 'child']);
201cb0ef41Sopenharmony_ci  proc.on('exit', common.mustCall(function(exitCode) {
211cb0ef41Sopenharmony_ci    assert.strictEqual(exitCode, 0);
221cb0ef41Sopenharmony_ci  }));
231cb0ef41Sopenharmony_ci  return;
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') {
271cb0ef41Sopenharmony_ci  [0, 1, 2].forEach((i) => fs.fstatSync(i));
281cb0ef41Sopenharmony_ci  return;
291cb0ef41Sopenharmony_ci}
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci// Run the script in a shell but close stdout and stderr.
321cb0ef41Sopenharmony_ciconst cmd = `"${process.execPath}" "${__filename}" child 1>&- 2>&-`;
331cb0ef41Sopenharmony_ciconst proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit' });
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciproc.on('exit', common.mustCall(function(exitCode) {
361cb0ef41Sopenharmony_ci  assert.strictEqual(exitCode, 0);
371cb0ef41Sopenharmony_ci}));
38