npm.io
1.0.1 • Published 12 years ago

spawn-handler

Licence
Version
1.0.1
Deps
0
Vulns
0
Weekly
0
Stars
1

spawn-handler

Actual version published on NPM

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 Tallefourtane - Nicolab.net
Nicolas Talle
Make a donation via Paypal

Keywords