https://github.com/strugee/node-smart-spawn
Spawn an async process and get back stdout, handling errors
https://github.com/strugee/node-smart-spawn
async-process hacktoberfest javascript nodejs process spawned-processes subprocess
Last synced: 23 days ago
JSON representation
Spawn an async process and get back stdout, handling errors
- Host: GitHub
- URL: https://github.com/strugee/node-smart-spawn
- Owner: strugee
- License: lgpl-3.0
- Created: 2016-10-30T00:19:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-01T01:25:17.000Z (over 5 years ago)
- Last Synced: 2025-04-04T22:08:57.225Z (10 months ago)
- Topics: async-process, hacktoberfest, javascript, nodejs, process, spawned-processes, subprocess
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/smart-spawn
- Size: 145 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
# `smart-spawn`
[](http://travis-ci.org/strugee/node-smart-spawn)
[](https://coveralls.io/github/strugee/node-smart-spawn?branch=master)
[](https://npmjs.com/package/smart-spawn)
[](https://greenkeeper.io/)
Spawn an async process and get back stdout, handling errors
## Installation
npm install smart-spawn
## Usage
You need Node 6+. It'll probably run on 0.10, 0.12 and 4 too, but the test suite doesn't cover those versions, so you're on your own. And you should upgrade anyway because those are horribly insecure.
```js
var smartSpawn = require('smart-spawn');
var process = smartSpawn('ls', ['-l'], process.cwd(), function(err, stdout) {
if (err) throw err;
console.log(stdout);
}
```
## Arguments
Arguments are, in order: the name of the process to spawn, arguments passed to the subprocess, the subprocess' working directory, and a callback function.
The callback receives two arguments. The first is an `Error` object which is passed if the process couldn't be spawned or if it exited with a nonzero exit code, otherwise it's `undefined`. The second is the process' stdout upon its completion (regardless of any errors that may have occured).
## Return value
`smart-spawn` will return an instance of [`ChildProcess`][1] representing the spawned subprocess.
## License
LGPL 3.0+
## Author
AJ Jordan
[1]: https://nodejs.org/api/child_process.html#child_process_class_childprocess