Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ralphtheninja/await-spawn
child_process.spawn() wrapped in a Promise
https://github.com/ralphtheninja/await-spawn
async await child-process promise spawn
Last synced: 23 days ago
JSON representation
child_process.spawn() wrapped in a Promise
- Host: GitHub
- URL: https://github.com/ralphtheninja/await-spawn
- Owner: ralphtheninja
- License: mit
- Created: 2017-08-20T13:56:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-16T14:54:31.000Z (almost 4 years ago)
- Last Synced: 2024-05-13T16:25:29.693Z (9 months ago)
- Topics: async, await, child-process, promise, spawn
- Language: JavaScript
- Size: 32.2 KB
- Stars: 39
- Watchers: 2
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# await-spawn
> `child_process.spawn()` wrapped in a `Promise` for doing async/await.
[![npm](https://img.shields.io/npm/v/await-spawn.svg)](https://www.npmjs.com/package/await-spawn)
![Node version](https://img.shields.io/node/v/await-spawn.svg)
[![Build Status](https://travis-ci.org/ralphtheninja/await-spawn.svg?branch=master)](https://travis-ci.org/ralphtheninja/await-spawn)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)## Install
```
$ npm i await-spawn -S
```## Usage
```js
const spawn = require('await-spawn')const main = async () => {
try {
const bl = await spawn('ls', ['-al'])
console.log(bl.toString())
} catch (e) {
console.log(e.stderr.toString())
}
}main()
```## Api
Exposes a single function, which has the same api as `child_process.spawn()`.
Returns a `Promise` with `.child` set to the spawned child process. The `Promise` resolves to the buffered output of `child.stdout` in the form of a [`BufferList`] object.
If there was an error, the `Promise` rejects with an `Error` object, which has the following extra properties:
* `code` the error code
* `stdout` the buffered output of `stdout` in the form of a [`BufferList`] object
* `stderr` the buffered output of `stderr` in the form of a [`BufferList`] objectNote that `child.stdout` doesn't exist if `options.stdio === 'inherit'`, so the `Promise` resolves to `''`.
## License
MIT
[`BufferList`]: https://github.com/rvagg/bl