Skip to content
Myr

Improve the readme usage examples (#385)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Cleanup & label examples * Update readme.md * Update readme.md

authored by Dan Levy · committed by Sindre Sorhus · parent 4f49253 · Browse files · 1 file+32 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+32 added−8 removed

  • other:+32 added−8 removed

1 file+32 added−8 removed

modified:readme.md+32 added-8 removed
39 unmodified lines
40 //=> 'unicorns'41})();42```4344Additional examples:44### Pipe the child process stdout to the parent4546```js47const execa = require('execa');4849(async () => {50 // Pipe the child process stdout to the current stdout51 execa('echo', ['unicorns']).stdout.pipe(process.stdout);49execa('echo', ['unicorns']).stdout.pipe(process.stdout);50```5152### Handling Errors5354```js55const execa = require('execa');5657(async () => {58 // Catching an error59 try {60 await execa('unknown', ['command']);61 } catch (error) {
18 unmodified lines
80 }81 */82 }8384})();85```8680 // Cancelling a spawned process87### Cancelling a spawned process8889```js90const execa = require('execa');9192(async () => {93 const subprocess = execa('node');9495 setTimeout(() => {96 subprocess.cancel();97 }, 1000);9899 try {100 await subprocess;101 } catch (error) {102 console.log(subprocess.killed); // true103 console.log(error.isCanceled); // true104 }91})();105})()106```10793// Catching an error with a sync method108### Catching an error with the sync method109110```js111try {112 execa.sync('unknown', ['command']);113} catch (error) {114 console.log(error);
16 unmodified lines
131 killed: false132 }133 */134}135```136119// Kill a process with SIGTERM, and after 2 seconds, kill it with SIGKILL137### Kill a process138139Using SIGTERM, and after 2 seconds, kill it with SIGKILL.140141```js142const subprocess = execa('node');143144setTimeout(() => {145 subprocess.kill('SIGTERM', {146 forceKillAfterTimeout: 2000147 });148}, 1000);149```150151152## API153154### execa(file, arguments, [options])155
446 unmodified lines