Skip to content
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: improve child_process.markdown copy #4383

Closed

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Dec 21, 2015

General improvements to child_process.markdown

@jasnell jasnell added child_process Issues and PRs related to the child_process subsystem. doc Issues and PRs related to the documentations. labels Dec 21, 2015
assert.equal(child.stdio[2], null);
assert.equal(child.stdio[2], child.stderr);
Pipes for `stdin`, `stdout` and `stderr` are established between the parent
Node.js process and the created child. It is possible to stream data through
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace "created" with "spawned" here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are only established when spawn is called with pipe as an option, or fork with silent: true. Unless I misunderstand the diff, this statement seems much more sweeping than is accurate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will clarify that this is the default behavior

@cjihrig
Copy link
Contributor

cjihrig commented Dec 22, 2015

Left a bunch of comments, but generally LGTM

and asynchronous alternatives to `child_process.spawn()`, each of which are
documented fully [below][]:

* `child_process.exec()`: spawns a shell and runs a command within that shell.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... "returning the stdout and stderr when the command completes". <--- that last is the very important distinction between the exec* and the spawn/fork.

be launched using `child_process.execFile()` (or even `child_process.spawn()`).
When running on Windows, `.bat` and `.cmd` files can only be invoked using
either `child_process.exec()` or by spawning `cmd.exe` and passing the `.bat`
or `.cmd` file as an argument.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(which is what child_process.exec() does). <-- worth mentioning? to demystify?

@sam-github
Copy link
Contributor

@jasnell Looks like you addressed all my comments, I remembered a couple other useful tidbits of info, though.

@jasnell
Copy link
Member Author

jasnell commented Dec 24, 2015

@sam-github ... ok, pushed another set of edits.

@jasnell
Copy link
Member Author

jasnell commented Dec 28, 2015

@nodejs/collaborators ... can I ask for some additional review and sign off on this? Thank you!

General improvements to child_process.markdown
@jasnell jasnell force-pushed the doc-child-process-improvements branch from 3631046 to f53b65d Compare December 28, 2015 16:40
@cjihrig
Copy link
Contributor

cjihrig commented Dec 29, 2015

LGTM

sending messages between parent and child.
* `child_process.execSync()`: a synchronous version of
`child_process.exec()` that *will* block the Node.js event loop.
* `child_process.execFileSync()`: a synchronous version of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to list the Sync versions right below their asynchronous counterpart?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep them grouped by async vs sync

jasnell added a commit that referenced this pull request Dec 30, 2015
General improvements to child_process.markdown

PR-URL: #4383
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@jasnell
Copy link
Member Author

jasnell commented Dec 30, 2015

Landed in 7d5c1b5. Can make additional improvements if necessary in a separate PR

@jasnell jasnell closed this Dec 30, 2015

const exec = require('child_process').execFile;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, this code example doesn't work even on Unix-like platforms. Since there's no shell wrapper,

  1. file must be an absolute path to executable.
  2. args must contain all the command line arguments for file.
  3. All paths within args must be absolute as well.
  4. Stdio redirection is not possible.

Here's an alternative I whipped up that should work on all Unix-like platforms. As always, feel free to use none, some, or all of it.

const execFile = require('child_process').execFile;
const child = execFile('/bin/cat', ['/etc/paths'], (error, stdout, stderr) => {
  if (error) {
    throw error;
  }
  console.log(stdout);
});

@jasnell
Copy link
Member Author

jasnell commented Dec 30, 2015

@ryansobol ... can I ask you for a quick PR to update the example? :-) Thank you!

@ryansobol
Copy link
Contributor

@jasnell No problem. See #4504

Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request Jan 6, 2016
General improvements to child_process.markdown

PR-URL: nodejs#4383
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@MylesBorins
Copy link
Contributor

@jasnell this is not merging cleanly, can you backport this please.

@jasnell
Copy link
Member Author

jasnell commented Jan 7, 2016

@thealphanerd ..yes, I'll work on backporting all of these kind of doc changes. They may not all make it into v4.2.5 but I'll work on them

@jasnell
Copy link
Member Author

jasnell commented Jan 29, 2016

@thealphanerd ... I'll be working on porting this to LTS early next week.

jasnell added a commit to jasnell/node that referenced this pull request Feb 19, 2016
General improvements to child_process.markdown

PR-URL: nodejs#4383
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
MylesBorins pushed a commit that referenced this pull request Feb 22, 2016
General improvements to child_process.markdown

PR-URL: #4383
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
MylesBorins pushed a commit that referenced this pull request Feb 22, 2016
General improvements to child_process.markdown

PR-URL: #4383
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 2, 2016
General improvements to child_process.markdown

PR-URL: #4383
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
General improvements to child_process.markdown

PR-URL: nodejs#4383
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
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.

5 participants