Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a28db5f

Browse filesBrowse files
ltcirotargos
authored andcommitted
doc: add example of event close for child_process
PR-URL: #28376 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent fa82cbc commit a28db5f
Copy full SHA for a28db5f

File tree

Expand file treeCollapse file tree

1 file changed

+17
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/child_process.md‎

Copy file name to clipboardExpand all lines: doc/api/child_process.md
+17Lines changed: 17 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,23 @@ The `'close'` event is emitted when the stdio streams of a child process have
914914
been closed. This is distinct from the [`'exit'`][] event, since multiple
915915
processes might share the same stdio streams.
916916

917+
```js
918+
const { spawn } = require('child_process');
919+
const ls = spawn('ls', ['-lh', '/usr']);
920+
921+
ls.stdout.on('data', (data) => {
922+
console.log(`stdout: ${data}`);
923+
});
924+
925+
ls.on('close', (code) => {
926+
console.log(`child process close all stdio with code ${code}`);
927+
});
928+
929+
ls.on('exit', (code) => {
930+
console.log(`child process exited with code ${code}`);
931+
});
932+
```
933+
917934
### Event: 'disconnect'
918935
<!-- YAML
919936
added: v0.7.2

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.