var childProcess = cp.spawnSync(command, args, {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
encoding: 'utf-8'
});
childProcess.output always eq [null, null, null]
process.stdout.write hook doesn't give me any output
var childProcess = cp.spawnSync(command, args, {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
encoding: 'utf-8'
});
childProcess.output always eq [null, null, null]
process.stdout.write hook doesn't give me any output
If you don't use 'pipe'
then childProcess.output
will not contain the output.
var cp = require('child_process');
var command = 'echo';
var args = ['hello', 'world'];
var childProcess = cp.spawnSync(command, args, {
cwd: process.cwd(),
env: process.env,
stdio: 'pipe',
encoding: 'utf-8'
});
console.log(childProcess.output); // [ null, 'hello world\n', '' ]
This is sorta kinda indicated in the documentation for child.stdout
and elsewhere, but it's not entirely unambiguous. (By all means, if you wish to see it improved, open a pull request against the Node.js repo.)
childProcess.output[1] #=> 'hello world\n'
–
Countess Use this for in-process displaying of progress:
var cp = require('child_process');
var command = 'echo';
var args = ['hello', 'world'];
var childProcess = cp.spawnSync(command, args, {
cwd: process.cwd(),
env: process.env,
stdio: [process.stdin, process.stdout, process.stderr],
encoding: 'utf-8'
});
So you replace string 'pipe'
with the array [process.stdin, process.stdout, process.stderr]
.
stdout
. It does show how to inspect/display stdout, but I believe @Adonic was asking for a way to store stdout and display it (via stdio: 'inherit'
). stdio: [process.stdin, process.stdout, process.stderr]
is equivalent to stdio: 'inherit'
. So, effectively, this solution is the same as the example in the original question. –
Koger stdio: [process.stdin, process.stdout, process.stderr]
is equivalent to the OP's stdio: 'inherit'
. –
Bridesmaid © 2022 - 2024 — McMap. All rights reserved.
'inherit'
in order to keep the progress display but I cannot hookstdout.write
or listen fordata
event... – Guttaperchastdio: [0, isOutputNeeded ? 'pipe' : 1, 2],
– Adonic