The program/script to execute.
Optional
arguments: readonly string[]Arguments to pass to file
on execution.
Optional
options: Options<string>A child_process
instance, which is enhanced to also be a Promise
for a result Object
with stdout
and stderr
properties.
import execa = require('execa');
(async () => {
const {stdout} = await execa('echo', ['unicorns']);
console.log(stdout);
//=> 'unicorns'
// Cancelling a spawned process
const subprocess = execa('node');
setTimeout(() => { spawned.cancel() }, 1000);
try {
await subprocess;
} catch (error) {
console.log(subprocess.killed); // true
console.log(error.isCanceled); // true
}
})();
// Pipe the child process stdout to the current stdout
execa('echo', ['unicorns']).stdout.pipe(process.stdout);
Optional
arguments: readonly string[]Optional
options: Options<null>Optional
options: Options<string>Optional
options: Options<null>
Execute a file.
Think of this as a mix of
child_process.execFile
andchild_process.spawn
.