2015-11-30 02:41:51 -08:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
2016-07-19 02:03:42 +05:30
|
|
|
const cp = require('child_process');
|
2015-11-30 02:41:51 -08:00
|
|
|
const assert = require('assert');
|
|
|
|
|
2016-05-29 12:21:02 -04:00
|
|
|
// Windows' `echo` command is a built-in shell command and not an external
|
|
|
|
// executable like on *nix
|
|
|
|
const opts = { shell: common.isWindows };
|
|
|
|
|
|
|
|
const p = cp.spawn('echo', [], opts);
|
2015-11-30 02:41:51 -08:00
|
|
|
|
2018-10-12 10:20:32 -07:00
|
|
|
p.on('close', common.mustCall((code, signal) => {
|
2015-11-30 02:41:51 -08:00
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
assert.strictEqual(signal, null);
|
2016-02-02 00:57:24 -05:00
|
|
|
spawnWithReadable();
|
2015-11-30 02:41:51 -08:00
|
|
|
}));
|
|
|
|
|
|
|
|
p.stdout.read();
|
|
|
|
|
2018-10-12 10:20:32 -07:00
|
|
|
const spawnWithReadable = () => {
|
2016-02-02 00:57:24 -05:00
|
|
|
const buffer = [];
|
2016-05-29 12:21:02 -04:00
|
|
|
const p = cp.spawn('echo', ['123'], opts);
|
2018-10-12 10:20:32 -07:00
|
|
|
p.on('close', common.mustCall((code, signal) => {
|
2016-02-02 00:57:24 -05:00
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
assert.strictEqual(signal, null);
|
|
|
|
assert.strictEqual(Buffer.concat(buffer).toString().trim(), '123');
|
|
|
|
}));
|
2018-10-12 10:20:32 -07:00
|
|
|
p.stdout.on('readable', () => {
|
2016-02-02 00:57:24 -05:00
|
|
|
let buf;
|
2022-01-20 06:47:03 -08:00
|
|
|
while ((buf = p.stdout.read()) !== null)
|
2016-02-02 00:57:24 -05:00
|
|
|
buffer.push(buf);
|
|
|
|
});
|
2018-10-12 10:20:32 -07:00
|
|
|
};
|