Skip to content
Myr

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 file

Take it

add code coverageSindre Sorhusbefore adoptiondd585bf

line 1why, one step back
1# execa [![Build Status: Linux](https://travis-ci.org/sindresorhus/execa.svg?branch=master)](https://travis-ci.org/sindresorhus/execa) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/x5ajamxtjtt93cqv/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/execa/branch/master) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/execa/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/execa?branch=master)

initSindre Sorhusbefore adoptionbc16d6b

line 2
2

tweaksSindre Sorhusbefore adoptione3505a8

line 3why, one step back
3> A better [`child_process`](https://nodejs.org/api/child_process.html)

initSindre Sorhusbefore adoptionbc16d6b

lines 4–10
4
56## 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 back
11- [Improved Windows support.](https://github.com/IndigoUnited/node-cross-spawn#why)

initSindre Sorhusbefore adoptionbc16d6b

line 12
12- Higher max buffer. 10 MB instead of 200 KB.

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 13why, one step back
13- [Executes locally installed binaries by name.](#preferlocal)

Add `cleanup` option (#53)Friedel Ziegelmayerbefore adoptiondbd9acd

line 14why, one step back
14- [Cleans up spawned processes when the parent process dies.](#cleanup)

initSindre Sorhusbefore adoptionbc16d6b

lines 15–33
15
1617## 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});33

remove deprecated `execa.spawn()` from the readmeSindre Sorhusbefore adoption037bfb4

lines 34–36why, one step back
34// pipe the child process stdout to the current stdout
35execa('echo', ['unicorns']).stdout.pipe(process.stdout);36

initSindre Sorhusbefore adoptionbc16d6b

lines 37–40
37execa.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 back
41
42// 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 back
51 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 back
54 }
55 */56});

initSindre Sorhusbefore adoptionbc16d6b

lines 57–63
57```
585960## API6162### execa(file, [arguments], [options])63

add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c

line 64why, one step back
64Execute a file.

initSindre Sorhusbefore adoptionbc16d6b

lines 65–67
65
66Same options as [`child_process.execFile`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback).67

remove deprecated `execa.spawn()` from the readmeSindre Sorhusbefore adoption037bfb4

line 68why, one step back
68Think of this as a mix of `child_process.execFile` and `child_process.spawn`.

initSindre Sorhusbefore adoptionbc16d6b

line 69
69

remove deprecated `execa.spawn()` from the readmeSindre Sorhusbefore adoption037bfb4

line 70why, one step back
70Returns 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 back
71

add `execa.stdout()` shortcut (#14)Sindre Sorhusbefore adoption868f505

lines 72–79why, one step back
72### 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`.79

initSindre Sorhusbefore adoptionbc16d6b

lines 80–85
80### 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).85

return the child process instead of a promise. (#18)James Talmagebefore adoption99f10ba

line 86why, one step back
86Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess).

initSindre Sorhusbefore adoptionbc16d6b

line 87
87

return the child process instead of a promise. (#18)James Talmagebefore adoption99f10ba

line 88why, one step back
88The `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 back
89

add `execa.sync()` (#7)Sindre Sorhusbefore adoption9345d2c

lines 90–93why, one step back
90### execa.sync(file, [arguments], [options])
9192Execute a file synchronously.93

add `execa.shellSync()`Sindre Sorhusbefore adoption71a58ee

lines 94–95why, one step back
94Same 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 back
96Returns 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 back
97
98### 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 back
103

[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)James Talmagebefore adoptiona8f2100

line 104why, one step back
104Returns 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 back
105

initSindre Sorhusbefore adoptionbc16d6b

lines 106–107
106### options
107

meta tweaksSindre Sorhusbefore adoption858af26

line 108why, one step back
108Additional options:

initSindre Sorhusbefore adoptionbc16d6b

lines 109–111
109
110#### stripEof111

Merge pull request #3 from sindresorhus/local-binsSindre Sorhusbefore adoptiona0c035c

line 112why, one step back
112Type: `boolean`<br>

initSindre Sorhusbefore adoptionbc16d6b

lines 113–115
113Default: `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 back
116
117#### 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')`.

initSindre Sorhusbefore adoptionbc16d6b

line 124
124

add `input` optionJames Talmagebefore adoption605a674

lines 125–131why, one step back
125#### input
126127Type: `string` `Buffer` `ReadableStream`128129Write some input to the `stdin` of your binary.<br>130Streams are not allowed when using the synchronous methods.131

Add `reject` option (#40)Kevin Mårtenssonbefore adoption9bafd76

lines 132–136why, one step back
132#### reject
133134Type: `boolean`<br>135Default: `true`136

correct `reject` option descriptionSindre Sorhusbefore adoption98a647a

line 137why, one step back
137Setting 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 back
138

Add `cleanup` option (#53)Friedel Ziegelmayerbefore adoptiondbd9acd

lines 139–144why, one step back
139#### cleanup
140141Type: `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 back
145

initSindre Sorhusbefore adoptionbc16d6b

lines 146–148
146
147## License148

meta tweaksSindre Sorhusbefore adoption858af26

line 149why, one step back
149MIT © [Sindre Sorhus](https://sindresorhus.com)