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)
3 > A better [`child_process`](https://nodejs.org/api/child_process.html)
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.
11 - [Improved Windows support.](https://github.com/IndigoUnited/node-cross-spawn#why)
12 - Higher max buffer. 10 MB instead of 200 KB.
13 - [Executes locally installed binaries by name.](#preferlocal)
14 - [Cleans up spawned processes when the parent process dies.](#cleanup)
20 $ npm install --save execa
27 const execa = require('execa');
29 execa('echo', ['unicorns']).then(result => {
30 console.log(result.stdout);
34 // pipe the child process stdout to the current stdout
35 execa('echo', ['unicorns']).stdout.pipe(process.stdout);
37 execa.shell('echo unicorns').then(result => {
38 console.log(result.stdout);
42 // example of catching an error
43 execa.shell('exit 3').catch(error => {
47 message: 'Command failed: /bin/sh -c exit 3'
51 cmd: '/bin/sh -c exit 3',
63 ### execa(file, [arguments], [options])
67 Same options as [`child_process.execFile`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback).
69 Think of this as a mix of `child_process.execFile` and `child_process.spawn`.
71 Returns 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.
73 ### execa.stdout(file, [arguments], [options])
75 Same as `execa()`, but returns only `stdout`.
77 ### execa.stderr(file, [arguments], [options])
79 Same as `execa()`, but returns only `stderr`.
81 ### execa.shell(command, [options])
83 Execute a command through the system shell. Prefer `execa()` whenever possible, as it's both faster and safer.
85 Same options as [`child_process.exec`](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback).
87 Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess).
89 The `child_process` instance is enhanced to also be promise for a result object with `stdout` and `stderr` properties.
91 ### execa.sync(file, [arguments], [options])
93 Execute a file synchronously.
95 Same 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`.
97 Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).
99 ### execa.shellSync(file, [options])
101 Execute a command synchronously through the system shell.
103 Same 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`.
105 Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).
116 [Strip EOF](https://github.com/sindresorhus/strip-eof) (last newline) from the output.
123 Prefer locally installed binaries when looking for a binary to execute.<br>
124 If you `$ npm install foo`, you can then `execa('foo')`.
128 Type: `string` `Buffer` `ReadableStream`
130 Write some input to the `stdin` of your binary.<br>
131 Streams are not allowed when using the synchronous methods.
138 Setting this to `false` resolves the promise with the error instead of rejecting it.
145 Keep track of the spawned process and `kill` it when the parent process exits.
150 MIT © [Sindre Sorhus](https://sindresorhus.com)