If you do not use 'pipe'
, then childProcess.output
will not contain an 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);
This is sorted as indicated in the documentation for child.stdout
and elsewhere, but it is not entirely straightforward. (In any case, if you want to improve it, open a Node.js repo port transfer request.)
source share