readme.md
This file
Path
readme.md
320 lines · 8.9 KiB · Markdown
Last changed by
Add a sentence about job search (#1027)ehmickybefore adoption5182195
History of this fileTake it
The walk stopped after 200 commits: lines older than a61a028 point at it.
Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 1–33why, one step back1<picture>2 <source media="(prefers-color-scheme: dark)" srcset="media/logo_dark.svg">3 <img alt="execa logo" src="media/logo.svg" width="400">4</picture>5<br>67[](https://codecov.io/gh/sindresorhus/execa)89> Process execution for humans1011<br>1213---1415<div align="center">16 <p>17 <p>18 <sup>19 <a href="https://github.com/sponsors/sindresorhus">Sindre's open source work is supported by the community</a>20 </sup>21 </p>22 <sup>Special thanks to:</sup>23 <br>24 <br>25 <a href="https://transloadit.com?utm_source=sindresorhus&utm_medium=referral&utm_campaign=sponsorship&utm_content=execa">26 <picture>27 <source width="360" media="(prefers-color-scheme: dark)" srcset="https://sindresorhus.com/assets/thanks/transloadit-logo-dark.svg">28 <source width="360" media="(prefers-color-scheme: light)" srcset="https://sindresorhus.com/assets/thanks/transloadit-logo.svg">29 <img width="360" src="https://sindresorhus.com/assets/thanks/transloadit-logo.svg" alt="Transloadit logo">30 </picture>31 </a>32 <br>33 <br>Meta tweaksSindre Sorhusbefore adoption1915060
lines 34–38why, one step back34 <a href="https://coderabbit.ai?utm_source=sindre&utm_medium=execa">35 <img width="300" src="https://sindresorhus.com/assets/thanks/coderabbit-logo.png" alt="CodeRabbit logo">36 </a>37 <br>38 <br>Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 39–45why, one step back39 </p>40</div>4142---4344<br>45Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 46why, one step back46Execa runs commands in your script, application or library. Unlike shells, it is [optimized](docs/bash.md) for programmatic usage. Built on top of the [`child_process`](https://nodejs.org/api/child_process.html) core module.Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 47why, one step back47Add a sentence about job search (#1027)ehmickybefore adoption5182195
lines 48–53why, one step back48---4950One of the maintainers [@ehmicky](https://github.com/ehmicky) is looking for a remote full-time position. Specialized in Node.js back-ends and CLIs, he led Netlify [Build](https://www.netlify.com/platform/core/build/), [Plugins](https://www.netlify.com/integrations/) and Configuration for 2.5 years. Feel free to contact him on [his website](https://www.mickael-hebert.com) or on [LinkedIn](https://www.linkedin.com/in/mickaelhebert/)!5152---53Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 54why, one step back54## FeaturesFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 55why, one step back55Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 56–70why, one step back56- [Simple syntax](#simple-syntax): promises and [template strings](docs/execution.md#template-string-syntax), like [`zx`](docs/bash.md).57- [Script](#script) interface.58- [No escaping](docs/escaping.md) nor quoting needed. No risk of shell injection.59- Execute [locally installed binaries](#local-binaries) without `npx`.60- Improved [Windows support](docs/windows.md): [shebangs](docs/windows.md#shebang), [`PATHEXT`](https://ss64.com/nt/path.html#pathext), [and more](https://github.com/moxystudio/node-cross-spawn?tab=readme-ov-file#why).61- [Detailed errors](#detailed-error) and [verbose mode](#verbose-mode), for [debugging](docs/debugging.md).62- [Pipe multiple subprocesses](#pipe-multiple-subprocesses) better than in shells: retrieve [intermediate results](docs/pipe.md#result), use multiple [sources](docs/pipe.md#multiple-sources-1-destination)/[destinations](docs/pipe.md#1-source-multiple-destinations), [unpipe](docs/pipe.md#unpipe).63- [Split](#split-into-text-lines) the output into text lines, or [iterate](#iterate-over-text-lines) progressively over them.64- Strip [unnecessary newlines](docs/lines.md#newlines).65- Get [interleaved output](#interleaved-output) from `stdout` and `stderr` similar to what is printed on the terminal.66- Retrieve the output [programmatically and print it](#programmatic--terminal-output) on the console at the same time.67- [Transform or filter](#transformfilter-output) the input and output with [simple functions](docs/transform.md).68- Redirect the [input](docs/input.md) and [output](docs/output.md) from/to [files](#files), [strings](#simple-input), [`Uint8Array`s](docs/binary.md#binary-input), [iterables](docs/streams.md#iterables-as-input) or [objects](docs/transform.md#object-mode).69- Pass [Node.js streams](docs/streams.md#nodejs-streams) or [web streams](#web-streams) to subprocesses, or [convert](#convert-to-duplex-stream) subprocesses to [a stream](docs/streams.md#converting-a-subprocess-to-a-stream).70- Ensure subprocesses exit even when they [intercept termination signals](docs/termination.md#forceful-termination), or when the current process [ends abruptly](docs/termination.md#current-process-exit).Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 71–77why, one step back7172## Install7374```sh75npm install execa76```77Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 78–103why, one step back78## Documentation7980Execution:81- ▶️ [Basic execution](docs/execution.md)82- 💬 [Escaping/quoting](docs/escaping.md)83- 💻 [Shell](docs/shell.md)84- 📜 [Scripts](docs/scripts.md)85- 🐢 [Node.js files](docs/node.md)86- 🌐 [Environment](docs/environment.md)87- ❌ [Errors](docs/errors.md)88- 🏁 [Termination](docs/termination.md)8990Input/output:91- 🎹 [Input](docs/input.md)92- 📢 [Output](docs/output.md)93- 📃 [Text lines](docs/lines.md)94- 🤖 [Binary data](docs/binary.md)95- 🧙 [Transforms](docs/transform.md)9697Advanced usage:98- 🔀 [Piping multiple subprocesses](docs/pipe.md)99- ⏳️ [Streams](docs/streams.md)100- 📞 [Inter-process communication](docs/ipc.md)101- 🐛 [Debugging](docs/debugging.md)102- 📎 [Windows](docs/windows.md)103- 🔍 [Difference with Bash and zx](docs/bash.md)Add documentation about TypeScript types (#1015)ehmickybefore adoptionf79e058
line 104why, one step back104- 🤓 [TypeScript](docs/typescript.md)Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 105why, one step back105- 📔 [API reference](docs/api.md)Add user guides (#989)ehmickybefore adoptionbe91ecf
line 106why, one step back106Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 107why, one step back107## ExamplesFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 108why, one step back108Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 109why, one step back109### ExecutionFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 110why, one step back110Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 111–112why, one step back111#### Simple syntax112Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 113–115why, one step back113```js114import {execa} from 'execa';115Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 116–117why, one step back116const {stdout} = await execa`npm run build`;117// Print command's outputFix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 118–120why, one step back118console.log(stdout);119```120Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 121why, one step back121#### ScriptFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 122why, one step back122Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 123why, one step back123```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
line 124why, one step back124import {$} from 'execa';Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 125why, one step back125Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 126–127why, one step back126const {stdout: name} = await $`cat package.json`.pipe`grep name`;127console.log(name);Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 128why, one step back128Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 129–130why, one step back129const branch = await $`git branch --show-current`;130await $`dep deploy --branch=${branch}`;Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 131why, one step back131Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 132–136why, one step back132await Promise.all([133 $`sleep 1`,134 $`sleep 2`,135 $`sleep 3`,136]);Allow template strings with all methods (#933)ehmickybefore adoption8074d85
line 137why, one step back137Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 138–140why, one step back138const directoryName = 'foo bar';139await $`mkdir /tmp/${directoryName}`;140```Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 141why, one step back141Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 142why, one step back142#### Local binariesFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 143why, one step back143Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 144–145why, one step back144```sh145$ npm install -D eslintFix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 146–148why, one step back146```147148```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
line 149why, one step back149await execa({preferLocal: true})`eslint`;Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 150–151why, one step back150```151Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 152why, one step back152#### Pipe multiple subprocessesFix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 153–154why, one step back153154```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 155–157why, one step back155const {stdout, pipedFrom} = await execa`npm run build`156 .pipe`sort`157 .pipe`head -n 2`;Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 158why, one step back158Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 159–164why, one step back159// Output of `npm run build | sort | head -n 2`160console.log(stdout);161// Output of `npm run build | sort`162console.log(pipedFrom[0].stdout);163// Output of `npm run build`164console.log(pipedFrom[0].pipedFrom[0].stdout);Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 165–166why, one step back165```166Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 167why, one step back167### Input/outputFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 168why, one step back168Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 169why, one step back169#### Interleaved outputFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 170why, one step back170`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
line 171why, one step back171```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 172–174why, one step back172const {all} = await execa({all: true})`npm run build`;173// stdout + stderr, interleaved174console.log(all);`.pipe()` shortcut for `$` (#840)ehmickybefore adoption316f562
lines 175–176why, one step back175```176Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 177why, one step back177#### Programmatic + terminal outputFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 178why, one step back178Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 179–182why, one step back179```js180const {stdout} = await execa({stdout: ['pipe', 'inherit']})`npm run build`;181// stdout is also printed to the terminal182console.log(stdout);Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 183–184why, one step back183```184Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 185why, one step back185#### FilesFix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 186–187why, one step back186187```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 188–189why, one step back188// Similar to: npm run build > output.txt189await execa({stdout: {file: './output.txt'}})`npm run build`;Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 190–191why, one step back190```191Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 192why, one step back192#### Simple inputFix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 193–194why, one step back193194```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
line 195why, one step back195const {stdout} = await execa({input: getInputString()})`sort`;Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 196–198why, one step back196console.log(stdout);197```198Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 199why, one step back199#### Split into text linesFix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 200–201why, one step back200201```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 202–205why, one step back202const {stdout} = await execa({lines: true})`npm run build`;203// Print first 10 lines204console.log(stdout.slice(0, 10).join('\n'));205```Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 206why, one step back206Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 207–216why, one step back207### Streaming208209#### Iterate over text lines210211```js212for await (const line of execa`npm run build`) {213 if (line.includes('WARN')) {214 console.warn(line);215 }216}Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 217–218why, one step back217```218Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 219why, one step back219#### Transform/filter outputFix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 220–221why, one step back220221```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
line 222why, one step back222let count = 0;Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 223why, one step back223Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 224–231why, one step back224// Filter out secret lines, then prepend the line number225const transform = function * (line) {226 if (!line.includes('secret')) {227 yield `[${count++}] ${line}`;228 }229};230231await execa({stdout: transform})`npm run build`;Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 232–233why, one step back232```233Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 234why, one step back234#### Web streamsAllow template strings with all methods (#933)ehmickybefore adoption8074d85
lines 235–236why, one step back235236```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 237–238why, one step back237const response = await fetch('https://example.com');238await execa({stdin: response.body})`sort`;Allow template strings with all methods (#933)ehmickybefore adoption8074d85
lines 239–240why, one step back239```240Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 241why, one step back241#### Convert to Duplex streamMake subprocess async iterable (#923)ehmickybefore adoption2e8e8c9
lines 242–244why, one step back242243```js244import {execa} from 'execa';Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 245–246why, one step back245import {pipeline} from 'node:stream/promises';246import {createReadStream, createWriteStream} from 'node:fs';Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9
line 247why, one step back247Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 248–252why, one step back248await pipeline(249 createReadStream('./input.txt'),250 execa`node ./transform.js`.duplex(),251 createWriteStream('./output.txt'),252);Make subprocess async iterable (#923)ehmickybefore adoption2e8e8c9
lines 253–254why, one step back253```254Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 255why, one step back255### DebuggingFix `timeout` option (#727)ehmickybefore adoptiona61a028
line 256why, one step back256Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 257–258why, one step back257#### Detailed error258Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 259why, one step back259```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
line 260why, one step back260import {execa, ExecaError} from 'execa';Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 261–262why, one step back261262try {Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 263why, one step back263 await execa`unknown command`;Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 264why, one step back264} catch (error) {Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 265–267why, one step back265 if (error instanceof ExecaError) {266 console.log(error);267 }Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 268why, one step back268 /*Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
lines 269–272why, one step back269 ExecaError: Command failed with ENOENT: unknown command270 spawn unknown ENOENT271 at ...272 at ... {Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 273why, one step back273 shortMessage: 'Command failed with ENOENT: unknown command\nspawn unknown ENOENT',Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 274–276why, one step back274 originalMessage: 'spawn unknown ENOENT',275 command: 'unknown command',276 escapedCommand: 'unknown command',Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
lines 277–278why, one step back277 cwd: '/path/to/cwd',278 durationMs: 28.217566,Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 279–281why, one step back279 failed: true,280 timedOut: false,281 isCanceled: false,Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
line 282why, one step back282 isTerminated: false,Add `error.isMaxBuffer` (#963)ehmickybefore adoption9e6e19e
line 283why, one step back283 isMaxBuffer: false,Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 284why, one step back284 code: 'ENOENT',Add `result|error.durationMs` (#896)ehmickybefore adoption7088091
lines 285–288why, one step back285 stdout: '',286 stderr: '',287 stdio: [undefined, '', ''],288 pipedFrom: []Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
lines 289–297why, one step back289 [cause]: Error: spawn unknown ENOENT290 at ...291 at ... {292 errno: -2,293 code: 'ENOENT',294 syscall: 'spawn unknown',295 path: 'unknown',296 spawnargs: [ 'command' ]297 }Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 298–301why, one step back298 }299 */300}301```Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 302–310why, one step back302303#### Verbose mode304305```js306await execa`npm run build`;307await execa`npm run test`;308```309310<img alt="execa verbose output" src="media/verbose.png" width="603">Fix `timeout` option (#727)ehmickybefore adoptiona61a028
lines 311–320why, one step back311312## Related313314- [gulp-execa](https://github.com/ehmicky/gulp-execa) - Gulp plugin for Execa315- [nvexeca](https://github.com/ehmicky/nvexeca) - Run Execa using any Node.js version316317## Maintainers318319- [Sindre Sorhus](https://github.com/sindresorhus)320- [@ehmicky](https://github.com/ehmicky)