-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 exec string is processed by shell #10921
Conversation
doc/api/child_process.md
Outdated
@@ -147,7 +147,9 @@ added: v0.1.90 | |||
* Returns: {ChildProcess} | |||
|
|||
Spawns a shell then executes the `command` within that shell, buffering any | |||
generated output. | |||
generated output. When specifying paths, spaces need to be dealt with |
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.
This isn't path specific, what about $
? Or args that are not paths? Can you change to make clear that the command line is being passed to the shell, and will be processed as a shell command, so beware of anything significant: white space, shell meta chars, etc.
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.
That's a good point! For some reason I was just focused on the path aspect 🤷♂️
What about something like:
...The command
string passed to the exec function is processed directly by the shell and special characters need to be dealt with
accordingly, eg. exec("'/path/to/test file/test.sh' arg1 arg2")
or
exec("echo \"Hello \$\\ World\"")
.
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.
looks good, but mention that the shell specials depend on the shell, and maybe link to where it docs what shell is used on what system?
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.
@sam-github I'll send another commit to update this PR to include these changes as well as those proposed by @Trott so that everyone can see a clean start point.
also commit message should say what it s doing "note that exec string is processed by shell", perhaps? |
doc/api/child_process.md
Outdated
@@ -147,7 +147,9 @@ added: v0.1.90 | |||
* Returns: {ChildProcess} | |||
|
|||
Spawns a shell then executes the `command` within that shell, buffering any | |||
generated output. | |||
generated output. When specifying paths, spaces need to be dealt with | |||
accordingly, eg. `exec("'/path/to/test file/test.sh' arg1 arg2")` or |
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.
Our code standards use single quotes instead of double quotes and I think all (or at least most?) of our examples follow that style too (except perhaps in cases where double quote avoids escaping).
I would recommend avoiding e.g.
and just spelling out for example
. Even better perhaps, just remove it entirely and put a colon after accordingly
. Then put the examples on separate lines by themselves.
...dealt with accordingly:
exec('"path...arg2'); exec('"path/to/test...arg2');
Ping @nodejs/documentation: Is using a code block that way OK when providing examples like that? I mean, it's not really a single block of code, but I'm not sure how else to do it? (Each one in its own code block?_
@codeman869 can you rebase, squash, and rewrite the commit message? |
17bc05d
to
54d60a2
Compare
@sam-github This has been squashed into 1 commit and the commit message was updated. |
@codeman869 It is difficult to find commits in logs when they don't try to describe the change. Did you see my suggestion?
You commit message is
In this commit message, "documentation" adds no value, the prefix already makes clear its a commit to the docs, and "update" adds no value, of course a git commit is updating something, so all we know is this commit touches some aspect of child_process.exec, a git commit message that could appear over and over for any kind of change to the child_process.exec docs, so not so helpful. Remove those words, and you have lots of space to give a hint as to what is being updated. See my examples. |
If you don't have time, I can rewrite the commit message when I land this, but if you are going to help out more on the project (as I hope you do), then it saves work if you produce better commit messages. |
@sam-github no, I want to do it right, so I'll update the message. Thanks for the input! 😄 |
54d60a2
to
b63555b
Compare
@sam-github I've amended my commit message per your suggestions, thank you! |
@Trott PTAL |
No objections from me on this. |
doc/api/child_process.md
Outdated
[shell](https://en.wikipedia.org/wiki/List_of_command-line_interpreters)) | ||
need to be dealt with accordingly: | ||
```js | ||
exec('"/path/to/test file/test.sh" arg1 arg2'); |
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.
It might be a good idea to explain the space thing in a comment.
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.
@thefourtheye - I'm sorry, can't believe I didn't see this. I'm not quite sure I'm following what you're saying. Can you explain a little bit more about what you mean by ? Thanks!
It might be a good idea to explain the space thing in a comment.
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.
@thefourtheye Do you want to clarify your comment? Or, @codeman869, do you want to take a stab at addressing the comment?
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.
@fhinkel I'll take a stab at it
@sam-github Is this waiting for anything further before being landed ? Also do I need to do anything about the test/arm and test/osx failures ? |
@codeman869 ... there is one comment from @thefourtheye that should be looked at, otherwise we'd just need to run CI again. |
Updates the Child Process Exec function documentation providing further information with regards to treating special characters in the command string function argument. Note that the exec string is processed by the shell. Updates description to show that special shell characters vary based on the shell with a link to the Wikipedia page regarding different command line interpreters and their associated operating systems. Updates example code to reside in separate lines using a codeblock and utilizes examples to comply with code standards by using single quotes. Fixes: nodejs#6803
b63555b
to
3ac049a
Compare
Okay, took a stab at @thefourtheye's recommendation and amended my commit, and rebased off the current master branch |
Ping @thefourtheye |
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.
Sorry for the delay people. Glad to see the helpful comments. Thanks @codeman869
Seeing as this is all approved - landed in fe1be39 Thanks for your contribution @codeman869 ! |
Updates the Child Process Exec function documentation providing further information with regards to treating special characters in the command string function argument. Note that the exec string is processed by the shell. Updates description to show that special shell characters vary based on the shell with a link to the Wikipedia page regarding different command line interpreters and their associated operating systems. Updates example code to reside in separate lines using a codeblock and utilizes examples to comply with code standards by using single quotes. PR-URL: #10921 Fixes: #6803 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Updates the Child Process Exec function documentation to provide more
information regarding how to deal with strings containing spaces
so that those spaces are not interpreted as separate arguments.
Fixes: #6803
Checklist
Affected core subsystem(s)
doc