spawn-handler
v1.0.1
Published
Simple handler for ChildProcess.spawn, it handles a child process spawned, then executes a callback when the process exits (optional).
Downloads
10
Maintainers
Readme
spawn-handler
Simple handler for ChildProcess.spawn of Node.js, it handles a child process spawned, then executes a callback when the process exits (optional).
spawn-handler has no external dependencies.
Quick start
Install
npm install spawn-handler
Usage
var spawn = require('spawn-handler');
spawn.run(command, [args], [options])
Shortcut of
var spawn = require('child_process').spawn;
spawn(command, [args], [options]);
Launches a new process (spawn) with the given command
.
See the Node.js doc (spawn) for more details.
var ls = spawn.run('ls', ['-lh', '/usr']);
ls.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ls.on('close', function (code) {
console.log('child process exited with code ' + code);
});
spawn.handle(child, [done], [name])
Spawn handler.
var ls = spawn.handle(spawn.run('ls', ['./']), function(code) {
console.log('Command exited with code ' + code);
}, 'List current directory');
ls.stdout.on('data', function(data) {
console.log('files: ' + data);
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
Testing
spawn-handler is tested with Unit.js and Mocha. Unit.js is a powerful and intuitive unit testing framework for javascript.
License
MIT (c) 2013, Nicolas Tallefourtane.
Author
| | |---| | Nicolas Talle | | |