A better
child_process
stdout.trim().$ npm install --save execaconst execa = ; ; // pipe the child process stdout to the current stdout stdout; execa; // example of catching an error execa;Execute a file.
Same options as child_process.spawn.
Think of this as a mix of child_process.execFile and child_process.spawn.
Returns a child_process instance, which is enhanced to also be a Promise for a result Object with stdout and stderr properties.
Same as execa(), but returns only stdout.
Same as execa(), but returns only stderr.
Execute a command through the system shell. Prefer execa() whenever possible, as it's both faster and safer.
Same options as child_process.spawn.
Returns a child_process instance.
The child_process instance is enhanced to also be promise for a result object with stdout and stderr properties.
Execute a file synchronously.
Same options as child_process.spawnSync, except the default encoding is utf8 instead of buffer.
Returns the same result object as child_process.spawnSync.
This method throws an Error if the command fails.
Execute a command synchronously through the system shell.
Same options as child_process.spawnSync, except the default encoding is utf8 instead of buffer.
Returns the same result object as child_process.spawnSync.
Additional options:
Type: boolean
Default: true
Strip EOF (last newline) from the output.
Type: boolean
Default: true
Prefer locally installed binaries when looking for a binary to execute.
If you $ npm install foo, you can then execa('foo').
Type: string Buffer ReadableStream
Write some input to the stdin of your binary.
Streams are not allowed when using the synchronous methods.
Type: boolean
Default: true
Setting this to false resolves the promise with the error instead of rejecting it.
Type: boolean
Default: true
Keep track of the spawned process and kill it when the parent process exits.
Let's say you want to show the output of a child process in real-time while also saving it to a variable.
const execa = ;const getStream = ; const stream = stdout; stream; ;MIT © Sindre Sorhus