11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst spawn = require('child_process').spawn; 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') { 71cb0ef41Sopenharmony_ci process.stdout.destroy(); 81cb0ef41Sopenharmony_ci process.stderr.destroy(); 91cb0ef41Sopenharmony_ci console.log('stdout'); 101cb0ef41Sopenharmony_ci process.stdout.write('rocks\n'); 111cb0ef41Sopenharmony_ci console.error('stderr'); 121cb0ef41Sopenharmony_ci setTimeout(function() { 131cb0ef41Sopenharmony_ci process.stderr.write('rocks too\n'); 141cb0ef41Sopenharmony_ci }, 10); 151cb0ef41Sopenharmony_ci return; 161cb0ef41Sopenharmony_ci} 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciconst proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' }); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cilet stdout = ''; 211cb0ef41Sopenharmony_ciproc.stdout.setEncoding('utf8'); 221cb0ef41Sopenharmony_ciproc.stdout.on('data', common.mustCallAtLeast(function(chunk) { 231cb0ef41Sopenharmony_ci stdout += chunk; 241cb0ef41Sopenharmony_ci}, 1)); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cilet stderr = ''; 271cb0ef41Sopenharmony_ciproc.stderr.setEncoding('utf8'); 281cb0ef41Sopenharmony_ciproc.stderr.on('data', common.mustCallAtLeast(function(chunk) { 291cb0ef41Sopenharmony_ci stderr += chunk; 301cb0ef41Sopenharmony_ci}, 1)); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciproc.on('exit', common.mustCall(function(exitCode) { 331cb0ef41Sopenharmony_ci assert.strictEqual(exitCode, 0); 341cb0ef41Sopenharmony_ci assert.strictEqual(stdout, 'stdout\nrocks\n'); 351cb0ef41Sopenharmony_ci assert.strictEqual(stderr, 'stderr\nrocks too\n'); 361cb0ef41Sopenharmony_ci})); 37