11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst cp = require('child_process'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// Windows' `echo` command is a built-in shell command and not an external 71cb0ef41Sopenharmony_ci// executable like on *nix 81cb0ef41Sopenharmony_ciconst opts = { shell: common.isWindows }; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst p = cp.spawn('echo', [], opts); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cip.on('close', common.mustCall((code, signal) => { 131cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 141cb0ef41Sopenharmony_ci assert.strictEqual(signal, null); 151cb0ef41Sopenharmony_ci spawnWithReadable(); 161cb0ef41Sopenharmony_ci})); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cip.stdout.read(); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciconst spawnWithReadable = () => { 211cb0ef41Sopenharmony_ci const buffer = []; 221cb0ef41Sopenharmony_ci const p = cp.spawn('echo', ['123'], opts); 231cb0ef41Sopenharmony_ci p.on('close', common.mustCall((code, signal) => { 241cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 251cb0ef41Sopenharmony_ci assert.strictEqual(signal, null); 261cb0ef41Sopenharmony_ci assert.strictEqual(Buffer.concat(buffer).toString().trim(), '123'); 271cb0ef41Sopenharmony_ci })); 281cb0ef41Sopenharmony_ci p.stdout.on('readable', () => { 291cb0ef41Sopenharmony_ci let buf; 301cb0ef41Sopenharmony_ci while ((buf = p.stdout.read()) !== null) 311cb0ef41Sopenharmony_ci buffer.push(buf); 321cb0ef41Sopenharmony_ci }); 331cb0ef41Sopenharmony_ci}; 34