Skip to content

Conversation

@reillylm
Copy link

In #53616, we added MJS snippets for the page. In the section about Windows batch files, we also combined two previous snippets who demonstrated the three ways of using spawn/exec described in the above paragraph.

The first snippet showed the spawn of cmd.exe way:

// On Windows Only...
const { spawn } = require('node:child_process');
const bat = spawn('cmd.exe', ['/c', 'my.bat']);

The other snippet showed the exec and spawn with shell: true ways:

// OR...
const { exec, spawn } = require('node:child_process');
exec('my.bat', (err, stdout, stderr) => {
const bat = spawn('"my script.cmd"', ['a', 'b'], { shell: true });

This makes these changes:

  • remove the // OR... comment, since we only have one snippet now, so there's nothing to "or" with :)
  • bring back the spawn('cmd.exe') example, which got lost in the shuffle
  • reorder the examples to match the way they're presented in the paragraph
  • remove the exec callback body, since the focus of the snippet is just the invocations of spawn/exec, not the usage of exec specifically
  • split the prose of the three ways into a list so it's easier to read

In nodejs#53616, we added MJS snippets for the page. In the section about
Windows batch files, we also combined two previous snippets who
demonstrated the three ways of using `spawn`/`exec` described in the above
paragraph.

The first snippet showed the `spawn` of `cmd.exe` way:

https://github.com/nodejs/node/blob/dc74f17f6c37b1bb2d675216066238f33790ed29/doc/api/child_process.md?plain=1#L112-L114

The other snippet showed the `exec` and `spawn` with `shell: true`
ways:

https://github.com/nodejs/node/blob/dc74f17f6c37b1bb2d675216066238f33790ed29/doc/api/child_process.md?plain=1#L130-L132
https://github.com/nodejs/node/blob/dc74f17f6c37b1bb2d675216066238f33790ed29/doc/api/child_process.md?plain=1#L141

This makes these changes:

- remove the `// OR...` comment, since we only have one snippet now, so
  there's nothing to "or" with :)
- bring back the `spawn('cmd.exe')` example, which got lost in the
  shuffle
- reorder the examples to match the way they're presented in the
  paragraph
- remove the `exec` callback body, since the focus of the snippet is
  just the invocations of `spawn`/`exec`, not the usage of `exec`
  specifically
- split the prose of the three ways into a list so it's easier to read
@nodejs-github-bot nodejs-github-bot added child_process Issues and PRs related to the child_process subsystem. doc Issues and PRs related to the documentations. labels Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

child_process Issues and PRs related to the child_process subsystem. doc Issues and PRs related to the documentations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants