Skip to content

kixxauth/command_runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Command Runner

Node.js module for running system commands and returning a Promise.

NPM

Summary

command_runner simply adds some Promise wrappers around the standard Node.js .exec() and .spawn() functions in the child_process module. The API is basically unchanged, but there are some changes in the implementation:

.exec()

Example:

var CR = require('command_runner');
CR.exec('ls -al').then(function (res) {
    console.log('exitCode: %i', res.exitCode); // 0
    console.log('exitSignal: %s', res.exitSignal); // null
    console.log('stdout: %s', res.stdout); // dir listing ....
    console.log('stderr: %s', res.stderr); // empty string
    console.log('errorMessage: %s', res.errorMessage); // undefined
});

command_runner.exec() always sets the exitCode and exitSignal, even if there is no error (to 0 and null, respectively), where the native Node.js child_process.exec() does not set them unless there is an error.

.spawn()

Example: Running the same command above, in a different way. The important distinction is that a shell is not invoked with spawn().

var CR = require('command_runner');
CR.spawn('ls', ['a', 'l']).then(function (res) {
    console.log('exitCode: %i', res.exitCode); // 0
    console.log('exitSignal: %s', res.exitSignal); // null
    console.log('stdout: %s', res.stdout); // dir listing ....
    console.log('stderr: %s', res.stderr); // empty string
    console.log('errorMessage: %s', res.errorMessage); // undefined
});

Unlike the native Node.js child_process.spawn(), command_runner.spawn() buffers stdout and stderr streams, and then resolves the promise with the results after the 'close' event is fired from the child process.

Copyright and License

Copyright: (c) 2015 by Kris Walker kris@kixx.name (http://www.kixx.name/)

Unless otherwise indicated, all source code is licensed under the MIT license. See MIT-LICENSE for details.

About

A Node.js module for running commands.

Resources

License

Stars

Watchers

Forks

Packages

No packages published