executive
An elegant child_process.spawn
. Automatically pipes stderr
and stdout
for
you in a non-blocking fashion, making it very useful with build tools and task
runners. Great async support with easy serial and parallel command execution.
Features
- Node.js callback, Promises and synchronous APIs.
- Serial execution by default, parallel optional.
- Automatically pipes
stderr
and stdout
by default. - Streams
stderr
and stdout
rather than blocking on command completion. - Automatically uses shell when command uses operators or globs.
- New-line delimited strings are automatically executed sequentially.
Install
$ npm install executive
Usage
No need to echo as stderr
and stdout
are piped by default.
var exec = require('executive');
exec('uglifyjs foo.js --compress --mangle > foo.min.js')
It's easy to be quiet too.
exec.quiet('uglifyjs foo.js --compress --mangle > foo.min.js')
Callbacks and promises supported.
exec.quiet('ls -l', function(err, stdout, stderr) {
var files = stdout.split('\n');
})
{stdout} = yield exec.quiet('ls -l')
var files = stdout.split('\n');
Automatically serializes commands.
exec(['ls', 'ls', 'ls'], function(err, stdout, stderr) {
});
exec(`
ls
ls
ls`)
Want to execute your commands in parallel? No problem.
{stdout} = yield exec.parallel(['ls', 'ls', 'ls'])
Options
Options are passed as the second argument to exec. Helper methods for
quiet
, interactive
, parallel
and sync
do what you expect.
exec('ls', {options: quiet})
and
exec.quiet('ls')
are equivalent.
options.interactive | exec.interactive
default false
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.interactive('vim', function(err) {
});
options.quiet | exec.quiet
default false
If you'd prefer not to pipe stdin
, stdout
, stderr
set quiet
to false
:
exec.quiet(['ls', 'ls'], function(err, stdout, stderr) {
});
options.sync | exec.sync
default false
Blocking version of exec. Returns {stdout, stderr}
or throws an error.
options.parallel | exec.parallel
default false
Uses parallel rather than serial execution of commands.
options.shell
default null
Force a shell to be used for command execution.
Great with cake
, grunt
, gulp
and other task runners. Even better mixed
with generator-based control flow libraries or async
/await
.
Complex example using shortcake
(which
provides a superset of cake's features, including
generator/promise task support):
require 'shortcake'
task 'package', 'Package project', ->
yield exec '''
mkdir -p dist/
rm -rf dist/*
'''
yield exec.parallel '''
cp manifest.json dist/
cp -rf assets/ dist/
cp -rf lib/ dist/
cp -rf views/ dist/
'''
yield exec '''
zip -r package.zip dist/
rm -rf dist/
'''