Elegant command execution.
An easy to use wrapper around
child_process.spawn, useful for Cakefiles and the like. Pipes
stdin so you don't have to. Think of it as a streaming
child_process.exec with a few extra goodies.
var exec = require'executive';exec'ls'// Done, no need to echo out as it's piped to stdout by default.;
Arguments are parsed out properly for you:
var exec = require'executive';exec'ls -AGF Foo\\ bar'// Note the escaped folder name.;
Also supports simple serial execution of commands:
var exec = require'executive';exec'ls' 'ls' 'ls'// All three ls commands are called in order.;
In the case of a failure, no additional commands will be executed:
exec'ls' 'aaaaa' 'ls'// First command succeeds, second blows up, third is never called.;
Commands can also be specified as a list of objects or a mix:
execcmd: 'ls'args: '-la''ls -la'cmd: 'ls'args: '-l'
Options may be passed as the second argument to exec and in the case of
interactive helper functions exist.
exec'ls' options: quiet
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
execinteractive'vim'// Edit your commit message or whatnot;
If you'd prefer not to pipe
execquiet'ls' 'ls'// Not a peep is heard, and both ls commands will be executed.;
In case you need to ignore errors during serial execution it's possible to set
exec'ls' 'aaaaaa' 'ls' safe: false// Both commands execute despite aaaaaa not being a valid executable.;
The spawned child process object is accessible when you exec a single program (not available when using the simple serial execution wrapper):
var exec = require'executive';child = execquiet'ls';childstdouton'data'// Do your own thing;
It's especially nice to use in a Cakefile:
exec = require 'executive'task 'package''Package project'->exec '''mkdir -p distrm -rf dist/*cp manifest.json distcp -rf assets distcp -rf lib distcp -rf views distzip -r package.zip distrm -rf dist'''split '\n'