GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: add example for `execFileSync` method and ref to stdio · nodejs/node@c0000f4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • child_process.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/child_process.md‎

Copy file name to clipboardExpand all lines: doc/api/child_process.md
+34-3Lines changed: 34 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ changes:
921921
* `input` {string|Buffer|TypedArray|DataView} The value which will be passed
922922
as stdin to the spawned process. If `stdio[0]` is set to `'pipe'`, Supplying
923923
this value will override `stdio[0]`.
924-
* `stdio` {string|Array} Child's stdio configuration. `stderr` by default will
924+
* `stdio` {string|Array} Child's stdio configuration.
925+
See [`child_process.spawn()`][]'s [`stdio`][]. `stderr` by default will
925926
be output to the parent process' stderr unless `stdio` is specified.
926927
**Default:** `'pipe'`.
927928
* `env` {Object} Environment key-value pairs. **Default:** `process.env`.
@@ -962,6 +963,34 @@ If the process times out or has a non-zero exit code, this method will throw an
962963
function. Any input containing shell metacharacters may be used to trigger
963964
arbitrary command execution.**
964965

966+
```js
967+
const { execFileSync } = require('node:child_process');
968+
969+
try {
970+
const stdout = execFileSync('my-script.sh', ['my-arg'], {
971+
// Capture stdout and stderr from child process. Overrides the
972+
// default behavior of streaming child stderr to the parent stderr
973+
stdio: 'pipe',
974+
975+
// Use utf8 encoding for stdio pipes
976+
encoding: 'utf8',
977+
});
978+
979+
console.log(stdout);
980+
} catch (err) {
981+
if (err.code) {
982+
// Spawning child process failed
983+
console.error(err.code);
984+
} else {
985+
// Child was spawned but exited with non-zero exit code
986+
// Error contains any stdout and stderr from the child
987+
const { stdout, stderr } = err;
988+
989+
console.error({ stdout, stderr });
990+
}
991+
}
992+
```
993+
965994
### `child_process.execSync(command[, options])`
966995

967996
<!-- YAML
@@ -991,7 +1020,8 @@ changes:
9911020
* `input` {string|Buffer|TypedArray|DataView} The value which will be passed
9921021
as stdin to the spawned process. If `stdio[0]` is set to `'pipe'`, Supplying
9931022
this value will override `stdio[0]`.
994-
* `stdio` {string|Array} Child's stdio configuration. `stderr` by default will
1023+
* `stdio` {string|Array} Child's stdio configuration.
1024+
See [`child_process.spawn()`][]'s [`stdio`][]. `stderr` by default will
9951025
be output to the parent process' stderr unless `stdio` is specified.
9961026
**Default:** `'pipe'`.
9971027
* `env` {Object} Environment key-value pairs. **Default:** `process.env`.
@@ -1069,7 +1099,8 @@ changes:
10691099
this value will override `stdio[0]`.
10701100
* `argv0` {string} Explicitly set the value of `argv[0]` sent to the child
10711101
process. This will be set to `command` if not specified.
1072-
* `stdio` {string|Array} Child's stdio configuration. **Default:** `'pipe'`.
1102+
* `stdio` {string|Array} Child's stdio configuration.
1103+
See [`child_process.spawn()`][]'s [`stdio`][]. **Default:** `'pipe'`.
10731104
* `env` {Object} Environment key-value pairs. **Default:** `process.env`.
10741105
* `uid` {number} Sets the user identity of the process (see setuid(2)).
10751106
* `gid` {number} Sets the group identity of the process (see setgid(2)).

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.