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: child_process exec string is processed by shell #10921

Closed
wants to merge 1 commit into from

Conversation

codeman869
Copy link
Contributor

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
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc

@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 20, 2017
@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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\"").

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@sam-github
Copy link
Contributor

also commit message should say what it s doing "note that exec string is processed by shell", perhaps?

@@ -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
Copy link
Member

@Trott Trott Jan 20, 2017

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?_

@sam-github
Copy link
Contributor

@codeman869 can you rebase, squash, and rewrite the commit message?

@codeman869
Copy link
Contributor Author

@sam-github This has been squashed into 1 commit and the commit message was updated.

@sam-github
Copy link
Contributor

@codeman869 It is difficult to find commits in logs when they don't try to describe the change. Did you see my suggestion?

doc: child_process exec string is processed by shell

You commit message is

doc: update child_process exec documentation

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.

@sam-github
Copy link
Contributor

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.

@codeman869
Copy link
Contributor Author

@sam-github no, I want to do it right, so I'll update the message. Thanks for the input! 😄

@codeman869 codeman869 changed the title doc: update child_process exec documentation doc: child_process exec string is processed by shell Jan 26, 2017
@codeman869
Copy link
Contributor Author

@sam-github I've amended my commit message per your suggestions, thank you!

@sam-github
Copy link
Contributor

@Trott PTAL

@Trott
Copy link
Member

Trott commented Jan 27, 2017

@Trott PTAL

No objections from me on this.

[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');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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

@codeman869
Copy link
Contributor Author

@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 ?
Thanks!

@jasnell
Copy link
Member

jasnell commented Feb 17, 2017

@codeman869 ... there is one comment from @thefourtheye that should be looked at, otherwise we'd just need to run CI again.

@jasnell
Copy link
Member

jasnell commented Feb 17, 2017

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
@codeman869
Copy link
Contributor Author

codeman869 commented Mar 27, 2017

Okay, took a stab at @thefourtheye's recommendation and amended my commit, and rebased off the current master branch

@jasnell
Copy link
Member

jasnell commented Apr 4, 2017

Ping @thefourtheye

Copy link
Contributor

@thefourtheye thefourtheye left a 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

@benjamingr
Copy link
Member

Seeing as this is all approved - landed in fe1be39

Thanks for your contribution @codeman869 !

@benjamingr benjamingr closed this Apr 16, 2017
benjamingr pushed a commit that referenced this pull request Apr 16, 2017
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>
@codeman869 codeman869 deleted the doc-child_process-exec branch April 16, 2017 23:52
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.

child_process.exec() fails with spaces in absolute or relative path to binary file
10 participants