readme.md
This file
Path
readme.md
149 lines · 4.6 KiB · Markdown
Last changed by
remove deprecated `execa.spawn()` from the readmeSindre Sorhusbefore adoption037bfb4
History of this fileTake it
add code coverageSindre Sorhusbefore adoptiondd585bf
line 1why, one step back1# execa [](https://travis-ci.org/sindresorhus/execa) [](https://ci.appveyor.com/project/sindresorhus/execa/branch/master) [](https://coveralls.io/github/sindresorhus/execa?branch=master)2tweaksSindre Sorhusbefore adoptione3505a8
line 3why, one step back3> A better [`child_process`](https://nodejs.org/api/child_process.html)initSindre Sorhusbefore adoptionbc16d6b
lines 4–10456## Why78- Promise interface.9- [Strips EOF](https://github.com/sindresorhus/strip-eof) from the output so you don't have to `stdout.trim()`.10- Supports [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) binaries cross-platform.Corrected Readme link to cross-spawn (was still cross-spawn-async) (#44)Michael Dreherbefore adoptionb41a69a
line 11why, one step back11- [Improved Windows support.](https://github.com/IndigoUnited/node-cross-spawn#why)12- Higher max buffer. 10 MB instead of 200 KB.Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 13why, one step back13- [Executes locally installed binaries by name.](#preferlocal)Add `cleanup` option (#53)Friedel Ziegelmayerbefore adoptiondbd9acd
line 14why, one step back14- [Cleans up spawned processes when the parent process dies.](#cleanup)initSindre Sorhusbefore adoptionbc16d6b
lines 15–33151617## Install1819```20$ npm install --save execa21```222324## Usage2526```js27const execa = require('execa');2829execa('echo', ['unicorns']).then(result => {30 console.log(result.stdout);31 //=> 'unicorns'32});33remove deprecated `execa.spawn()` from the readmeSindre Sorhusbefore adoption037bfb4
lines 34–36why, one step back34// pipe the child process stdout to the current stdout35execa('echo', ['unicorns']).stdout.pipe(process.stdout);36initSindre Sorhusbefore adoptionbc16d6b
lines 37–4037execa.shell('echo unicorns').then(result => {38 console.log(result.stdout);39 //=> 'unicorns'40});add example of failing command to the readmeSindre Sorhusbefore adoptionb72827e
lines 41–50why, one step back4142// example of catching an error43execa.shell('exit 3').catch(error => {44 console.log(error);45 /*46 {47 message: 'Command failed: /bin/sh -c exit 3'48 killed: false,49 code: 3,50 signal: null,add `stdout`/`stderr` to errorsSindre Sorhusbefore adoption0ea8aaf
lines 51–53why, one step back51 cmd: '/bin/sh -c exit 3',52 stdout: '',53 stderr: ''add example of failing command to the readmeSindre Sorhusbefore adoptionb72827e
lines 54–56why, one step back54 }55 */56});initSindre Sorhusbefore adoptionbc16d6b
lines 57–6357```585960## API6162### execa(file, [arguments], [options])63add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c
line 64why, one step back64Execute a file.initSindre Sorhusbefore adoptionbc16d6b
lines 65–676566Same options as [`child_process.execFile`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback).67remove deprecated `execa.spawn()` from the readmeSindre Sorhusbefore adoption037bfb4
line 68why, one step back68Think of this as a mix of `child_process.execFile` and `child_process.spawn`.69remove deprecated `execa.spawn()` from the readmeSindre Sorhusbefore adoption037bfb4
line 70why, one step back70Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties.meta tweaksSindre Sorhusbefore adoption858af26
line 71why, one step back71add `execa.stdout()` shortcut (#14)Sindre Sorhusbefore adoption868f505
lines 72–79why, one step back72### execa.stdout(file, [arguments], [options])7374Same as `execa()`, but returns only `stdout`.7576### execa.stderr(file, [arguments], [options])7778Same as `execa()`, but returns only `stderr`.79initSindre Sorhusbefore adoptionbc16d6b
lines 80–8580### execa.shell(command, [options])8182Execute a command through the system shell. Prefer `execa()` whenever possible, as it's both faster and safer.8384Same options as [`child_process.exec`](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback).85return the child process instead of a promise. (#18)James Talmagebefore adoption99f10ba
line 86why, one step back86Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess).87return the child process instead of a promise. (#18)James Talmagebefore adoption99f10ba
line 88why, one step back88The `child_process` instance is enhanced to also be promise for a result object with `stdout` and `stderr` properties.meta tweaksSindre Sorhusbefore adoption858af26
line 89why, one step back89add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c
lines 90–93why, one step back90### execa.sync(file, [arguments], [options])9192Execute a file synchronously.93add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee
lines 94–95why, one step back94Same options as [`child_process.execFileSync`](https://nodejs.org/api/child_process.html#child_process_child_process_execfilesync_file_args_options), except the default encoding is `utf8` instead of `buffer`.95[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)James Talmagebefore adoptiona8f2100
line 96why, one step back96Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee
lines 97–102why, one step back9798### execa.shellSync(file, [options])99100Execute a command synchronously through the system shell.101102Same options as [`child_process.execSync`](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options), except the default encoding is `utf8` instead of `buffer`.add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c
line 103why, one step back103[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)James Talmagebefore adoptiona8f2100
line 104why, one step back104Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).expose `.spawn`Sindre Sorhusbefore adoptionb65479c
line 105why, one step back105initSindre Sorhusbefore adoptionbc16d6b
lines 106–107106### options107meta tweaksSindre Sorhusbefore adoption858af26
line 108why, one step back108Additional options:initSindre Sorhusbefore adoptionbc16d6b
lines 109–111109110#### stripEof111Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
line 112why, one step back112Type: `boolean`<br>initSindre Sorhusbefore adoptionbc16d6b
lines 113–115113Default: `true`114115[Strip EOF](https://github.com/sindresorhus/strip-eof) (last newline) from the output.Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c
lines 116–123why, one step back116117#### preferLocal118119Type: `boolean`<br>120Default: `true`121122Prefer locally installed binaries when looking for a binary to execute.<br>123If you `$ npm install foo`, you can then `execa('foo')`.124add `input` optionJames Talmagebefore adoption605a674
lines 125–131why, one step back125#### input126127Type: `string` `Buffer` `ReadableStream`128129Write some input to the `stdin` of your binary.<br>130Streams are not allowed when using the synchronous methods.131Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76
lines 132–136why, one step back132#### reject133134Type: `boolean`<br>135Default: `true`136correct `reject` option descriptionSindre Sorhusbefore adoption98a647a
line 137why, one step back137Setting this to `false` resolves the promise with the error instead of rejecting it.Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76
line 138why, one step back138Add `cleanup` option (#53)Friedel Ziegelmayerbefore adoptiondbd9acd
lines 139–144why, one step back139#### cleanup140141Type: `boolean`<br>142Default: `true`143144Keep track of the spawned process and `kill` it when the parent process exits.remove deprecated `execa.spawn()` from the readmeSindre Sorhusbefore adoption037bfb4
line 145why, one step back145initSindre Sorhusbefore adoptionbc16d6b
lines 146–148146147## License148meta tweaksSindre Sorhusbefore adoption858af26
line 149why, one step back149MIT © [Sindre Sorhus](https://sindresorhus.com)