The program/script to execute.
Optionalarguments: readonly string[]Arguments to pass to file on execution.
Optionaloptions: 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);
Optionalarguments: readonly string[]Optionaloptions: Options<null>Optionaloptions: Options<string>Optionaloptions: Options<null>Same as execa() except both file and arguments are specified in a single command string. For example, execa('echo', ['unicorns']) is the same as execa.command('echo unicorns').
If the file or an argument contains spaces, they must be escaped with backslashes. This matters especially if command is not a constant but a variable, for example with __dirname or process.cwd(). Except for spaces, no escaping/quoting is needed.
The shell option must be used if the command uses shell-specific features, as opposed to being a simple file followed by its arguments.
The program/script to execute and its arguments.
Optionaloptions: Options<string>A child_process instance, which is enhanced to also be a Promise for a result Object with stdout and stderr properties.
Optionaloptions: Options<null>Same as execa.command() but synchronous.
The program/script to execute and its arguments.
Optionaloptions: SyncOptions<string>A result Object with stdout and stderr properties.
Optionaloptions: SyncOptions<null>Execute a Node.js script as a child process.
Same as execa('node', [scriptPath, ...arguments], options) except (like child_process#fork()):
- the current Node version and options are used. This can be overridden using the nodePath and nodeArguments options.
- the shell option cannot be used
- an extra channel ipc is passed to stdio
Node.js script to execute.
Optionalarguments: readonly string[]Arguments to pass to scriptPath on execution.
Optionaloptions: NodeOptions<string>A child_process instance, which is enhanced to also be a Promise for a result Object with stdout and stderr properties.
Optionalarguments: readonly string[]Optionaloptions: Options<null>Optionaloptions: Options<string>Optionaloptions: Options<null>Execute a file synchronously.
This method throws an Error if the command fails.
The program/script to execute.
Optionalarguments: readonly string[]Arguments to pass to file on execution.
Optionaloptions: SyncOptions<string>A result Object with stdout and stderr properties.
Optionalarguments: readonly string[]Optionaloptions: SyncOptions<null>Optionaloptions: SyncOptions<string>Optionaloptions: SyncOptions<null>
Execute a file.
Think of this as a mix of
child_process.execFileandchild_process.spawn.