EZ-Spawn
Simple, consistent sync/async process spawning
Features
-
Normalizes the results of spawn and spawnSync calls through the async
and sync
functions that ez-spawn provides.
-
Normalizes the arguments passed into the spawn
and spawnSync
-
Both return the same process object no matter how it is called.
-
Tested on Mac, Linux, and Windows as well as Node v4-7
Example
let sync = require('ez-spawn').sync;
let async = require('ez-spawn').async;
let process = sync('ls', '-al');
async('ls', '-a' '-l', (process) => {
console.log(process.status);
});
async('ls -al')
.then((process) => {
console.log(process.stdout);
})
.catch((err) => {
})
Installation
Node
Install using npm:
npm install ez-spawn
Then require it in your code:
let async = require("ez-spawn").async;
let sync = require("ez-spawn").sync;
API
sync(command, [arguments], [options])
Synchronously spawns a process and returns a Process
object
command
- The command string to be executed.arguments
- (optional) An array or a series of individual string parameters that are the arguments to be associated with the command
parameter.options
- (optional) The spawnSync options object.
async(command, [arguments], [options], callback?)
Asynchronously spawns a process and returns a promise or a callback if specified that contains a Process
object.
command
- The command string to be executed.arguments
- (optional) An array or a series of individual string parameters that are the arguments to be associated with the command
parameter.options
- (optional) The spawnSync options object.callback
- (optional) If a callback is not specified then spawned process results are returned as a Promise
Process
Both async and sync both return a Process
object that contains the following properties. It mirrors the object returned by spawnSync.
command
- The command that was used to spawn the process.args
- The command-line arguments that were passed to the process.pid
- The numeric process ID assigned by the operating system.stdout
- The process's standard output.stderr
- The process's error output.output
- All program output [stdin, stdout, stderr].exitCode
- The process's exit code.signal
- The signal used to kill the process, if applicable.error
- The error that occurred while spawning or killing the process, if any.toString()
- Returns the full command and arguments used to spawn the process.
Contributing
We welcome any contributions, enhancements, and bug-fixes. File an issue on GitHub and submit a pull request.
Building/Testing
To build/test the project locally on your computer:
-
Clone this repo
git clone hhttps://github.com/rkrauskopf/ez-spawn.git
-
Install dependencies
npm install
-
Run the tests
npm test
License
ez-spawn is 100% free and open-source, under the MIT license. Use it however you want.