1'use strict'; 2require('../common'); 3const assert = require('assert'); 4 5if (process.argv[2] === 'child') 6 process.stdout.end('foo'); 7else 8 parent(); 9 10function parent() { 11 const spawn = require('child_process').spawn; 12 const child = spawn(process.execPath, [__filename, 'child']); 13 let out = ''; 14 let err = ''; 15 16 child.stdout.setEncoding('utf8'); 17 child.stderr.setEncoding('utf8'); 18 19 child.stdout.on('data', function(c) { 20 out += c; 21 }); 22 child.stderr.on('data', function(c) { 23 err += c; 24 }); 25 26 child.on('close', function(code, signal) { 27 assert.strictEqual(code, 0); 28 assert.strictEqual(err, ''); 29 assert.strictEqual(out, 'foo'); 30 console.log('ok'); 31 }); 32} 33