spawn-handler

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i spawn-handler

Weekly Downloads

0

Version

1.0.1

License

none

Last publish

Collaborators

  • nicolab