cross-spawn-with-kill
Version:
Adds cross-platform `kill` function to cross-spawn processes
108 lines (83 loc) • 5.81 kB
Markdown
# cross-spawn-with-kill
Adds cross-platform `kill` function to cross-spawn processes
[![Build Status][build-badge]][build]
[![Code Coverage][coverage-badge]][coverage]
[![Dependencies][dependencyci-badge]][dependencyci]
[![version][version-badge]][package]
[![downloads][downloads-badge]][npm-stat]
[![MIT License][license-badge]][LICENSE]
[](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
[![Roadmap][roadmap-badge]][roadmap]
[![Examples][examples-badge]][examples]
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
[![Tweet][twitter-badge]][twitter]
## The problem
[`cross-spawn`](https://npmjs.com/package/cross-spawn) is a cross platform solution to node's `spawn`. However, it
doesn't provide a mechanism for "killing" the process after it's begun (in a cross platform manner).
## This solution
This solution provides a `kill` function on the `child` returned from `spawn` which will kill the corresponding process
when invoked. It does not work with `spawn.sync` as the process will be finished before your code could run anyway.
## Installation
This module is distributed via [npm][npm] which is bundled with [node][node] and should
be installed as one of your project's `dependencies`:
```
npm install --save cross-spawn-with-kill
```
## Usage
```javascript
const spawn = require('cross-spawn-with-kill')
const child = spawn('webpack')
child.kill() // <-- that's the ✨ magic ✨ extra function
```
## Inspiration
Big thank you goes to [@mysticatea](https://github.com/mysticatea) for his original work on
[npm-run-all](https://github.com/mysticatea/npm-run-all) from which
[this project was derived](https://github.com/mysticatea/npm-run-all/issues/59).
## Other Solutions
There are none that I'm aware of. [The issue](https://github.com/IndigoUnited/node-cross-spawn/issues/40) on
`cross-spawn` requesting this feature was rejected. Hence the creation of this module.
## Contributors
Thanks goes to these people ([emoji key][emojis]):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/cross-spawn-with-kill/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/cross-spawn-with-kill/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/kentcdodds/cross-spawn-with-kill/commits?author=kentcdodds) | [<img src="https://avatars.githubusercontent.com/u/1937871?v=3" width="100px;"/><br /><sub>Toru Nagashima</sub>](https://plus.google.com/u/0/+ToruNagashimax/)<br />[💻](https://github.com/kentcdodds/cross-spawn-with-kill/commits?author=mysticatea) |
| :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
## LICENSE
MIT
[npm]: https://www.npmjs.com/
[node]: https://nodejs.org
[build-badge]: https://img.shields.io/travis/kentcdodds/cross-spawn-with-kill.svg?style=flat-square
[build]: https://travis-ci.org/kentcdodds/cross-spawn-with-kill
[coverage-badge]: https://img.shields.io/codecov/c/github/kentcdodds/cross-spawn-with-kill.svg?style=flat-square
[coverage]: https://codecov.io/github/kentcdodds/cross-spawn-with-kill
[dependencyci-badge]: https://dependencyci.com/github/kentcdodds/cross-spawn-with-kill/badge?style=flat-square
[dependencyci]: https://dependencyci.com/github/kentcdodds/cross-spawn-with-kill
[version-badge]: https://img.shields.io/npm/v/cross-spawn-with-kill.svg?style=flat-square
[package]: https://www.npmjs.com/package/cross-spawn-with-kill
[downloads-badge]: https://img.shields.io/npm/dm/cross-spawn-with-kill.svg?style=flat-square
[npm-stat]: http://npm-stat.com/charts.html?package=cross-spawn-with-kill&from=2016-04-01
[license-badge]: https://img.shields.io/npm/l/cross-spawn-with-kill.svg?style=flat-square
[license]: https://github.com/kentcdodds/cross-spawn-with-kill/blob/master/other/LICENSE
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
[prs]: http://makeapullrequest.com
[donate-badge]: https://img.shields.io/badge/$-support-green.svg?style=flat-square
[donate]: http://kcd.im/donate
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
[coc]: https://github.com/kentcdodds/cross-spawn-with-kill/blob/master/other/CODE_OF_CONDUCT.md
[roadmap-badge]: https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square
[roadmap]: https://github.com/kentcdodds/cross-spawn-with-kill/blob/master/other/ROADMAP.md
[examples-badge]: https://img.shields.io/badge/%F0%9F%92%A1-examples-8C8E93.svg?style=flat-square
[examples]: https://github.com/kentcdodds/cross-spawn-with-kill/blob/master/other/EXAMPLES.md
[github-watch-badge]: https://img.shields.io/github/watchers/kentcdodds/cross-spawn-with-kill.svg?style=social
[github-watch]: https://github.com/kentcdodds/cross-spawn-with-kill/watchers
[github-star-badge]: https://img.shields.io/github/stars/kentcdodds/cross-spawn-with-kill.svg?style=social
[github-star]: https://github.com/kentcdodds/cross-spawn-with-kill/stargazers
[twitter]: https://twitter.com/intent/tweet?text=Check%20out%20cross-spawn-with-kill!%20https://github.com/kentcdodds/cross-spawn-with-kill%20%F0%9F%91%8D
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/kentcdodds/cross-spawn-with-kill.svg?style=social
[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key
[all-contributors]: https://github.com/kentcdodds/all-contributors