-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc, child_process: add esm snippets #53616
base: main
Are you sure you want to change the base?
Conversation
```js | ||
// OR... | ||
const { exec, spawn } = require('node:child_process'); | ||
exec('my.bat', (err, stdout, stderr) => { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
console.log(stdout); | ||
```mjs | ||
import { spawn } from 'node:child_process'; | ||
const spawned = spawn('my_command', ['arguments']); | ||
|
||
spawned.stdout.on('data', (data) => { | ||
console.log(data.toString()); | ||
}); | ||
|
||
// Script with spaces in the filename: | ||
const bat = spawn('"my script.cmd"', ['a', 'b'], { shell: true }); | ||
// or: | ||
exec('"my script.cmd" a b', (err, stdout, stderr) => { | ||
// ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were these removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were modified because in the original, because they are no longer recommended by Node.js. Using spawn
with a batch file (without shell: true
) isn't possible, so I figured that I'd remove the example while I was updating the file.
This PR adds ESM snippets to the documentation for
node:child_process
.In addition to this, some snippets were modified for readability (
message
instead ofm
, etc)