1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4 5const { spawn } = require('child_process'); 6for (const args of [[], ['-']]) { 7 const child = spawn(process.execPath, args, { 8 env: { ...process.env, 9 NODE_DEBUG: process.argv[2] 10 } 11 }); 12 const wanted = `${child.pid}\n`; 13 let found = ''; 14 15 child.stdout.setEncoding('utf8'); 16 child.stdout.on('data', function(c) { 17 found += c; 18 }); 19 20 child.stderr.setEncoding('utf8'); 21 child.stderr.on('data', function(c) { 22 console.error(`> ${c.trim().split('\n').join('\n> ')}`); 23 }); 24 25 child.on('close', common.mustCall(function(c) { 26 assert.strictEqual(c, 0); 27 assert.strictEqual(found, wanted); 28 })); 29 30 setTimeout(function() { 31 child.stdin.end('console.log(process.pid)'); 32 }, 1); 33} 34