1'use strict'; 2const common = require('../common'); 3const process = require('process'); 4 5let defaultShell; 6if (process.platform === 'linux' || process.platform === 'darwin') { 7 defaultShell = '/bin/sh'; 8} else if (process.platform === 'win32') { 9 defaultShell = 'cmd.exe'; 10} else { 11 common.skip('This is test exists only on Linux/Win32/OSX'); 12} 13 14const { execSync } = require('child_process'); 15const fs = require('fs'); 16const path = require('path'); 17const tmpdir = require('../common/tmpdir'); 18 19const tmpDir = tmpdir.path; 20tmpdir.refresh(); 21const tmpCmdFile = path.join(tmpDir, 'test-stdin-from-file-spawn-cmd'); 22const tmpJsFile = path.join(tmpDir, 'test-stdin-from-file-spawn.js'); 23fs.writeFileSync(tmpCmdFile, 'echo hello'); 24fs.writeFileSync(tmpJsFile, ` 25'use strict'; 26const { spawn } = require('child_process'); 27// Reference the object to invoke the getter 28process.stdin; 29setTimeout(() => { 30 let ok = false; 31 const child = spawn(process.env.SHELL || '${defaultShell}', 32 [], { stdio: ['inherit', 'pipe'] }); 33 child.stdout.on('data', () => { 34 ok = true; 35 }); 36 child.on('close', () => { 37 process.exit(ok ? 0 : -1); 38 }); 39}, 100); 40`); 41 42execSync(`${process.argv[0]} ${tmpJsFile} < ${tmpCmdFile}`); 43