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>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.
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.
Optional
options: Options<null>Same as execa.command()
but synchronous.
The program/script to execute and its arguments.
Optional
options: SyncOptions<string>A result Object
with stdout
and stderr
properties.
Optional
options: 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.
Optional
arguments: readonly string[]Arguments to pass to scriptPath
on execution.
Optional
options: NodeOptions<string>A child_process
instance, which is enhanced to also be a Promise
for a result Object
with stdout
and stderr
properties.
Optional
arguments: readonly string[]Optional
options: Options<null>Optional
options: Options<string>Optional
options: Options<null>Execute a file synchronously.
This method throws an Error
if the command fails.
The program/script to execute.
Optional
arguments: readonly string[]Arguments to pass to file
on execution.
Optional
options: SyncOptions<string>A result Object
with stdout
and stderr
properties.
Optional
arguments: readonly string[]Optional
options: SyncOptions<null>Optional
options: SyncOptions<string>Optional
options: SyncOptions<null>
Execute a file.
Think of this as a mix of
child_process.execFile
andchild_process.spawn
.