executive
An elegant
child_process.spawn
Executive is simple and intuitive interface to
child_process.spawn
with zero depdencies. Built-in support
for async and sync process creation, built-in flow control and automatic shell
make working with external processes in Node easy.
Features
- Async callback, promise and sync APIs
- Automatically pipes
stderr
andstdout
by default - Automatically uses shell when commands use builtins, globs or operators
- Built-in control flow with support for parallel and serial execution
- Mix simple string commands with functions and promises returning commands
- Multi-line strings parsed as multiple commands and executed sequentially
- Streams
stderr
andstdout
rather than blocking on command completion - Included TypeScript type definition
- Improved Windows support
- No external dependencies
Install
$ npm install executive --save-dev
Usage
No need to echo as stderr
and stdout
are piped by default.
It's easy to be quiet too.
exec
Callbacks and promises are both supported.
Automatically serializes commands.
// All three ls commands will be executed in order // Also executed in order
Want to execute your commands in parallel? No problem.
exec
Want to collect individual results? Easy.
a b c = await exec
Want to blend in Promises or pure functions? You got it.
exec
Options
Options are passed as the second argument to exec. Helper methods for
quiet
, interactive
, parallel
and sync
do what you expect.
and
exec
are equivalent.
options.interactive | exec.interactive
false
default If you need to interact with a program (your favorite text editor for instance)
or watch the output of a long running process (tail -f
), or just don't care
about checking stderr
and stdout
, set interactive
to true
:
exec
options.quiet | exec.quiet
false
default If you'd prefer not to pipe stdout
and stderr
set quiet
to true
:
exec
options.sync | exec.sync
false
default Blocking version of exec. Returns {stdout, stderr}
or throws an error.
options.parallel | exec.parallel
false
default Uses parallel rather than serial execution of commands.
options.shell
null
default Force a shell to be used for command execution.
options.strict
false
default Any non-zero exit status is treated as an error. Promises will be rejected and
an error will be thrown with exec.sync
if syncThrows
is enabled.
options.syncThrows
false
default Will cause exec.sync
to throw errors rather than returning them.
Extra
Great with sake
, grunt
, gulp
and other task runners. Even nicer with
async
and await
.
Fancy example using sake
:
You can find more usage examples in the tests.