0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

doc: child_process example for special chars

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: https://github.com/nodejs/node/pull/10921/
Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
Cody Deckard 2017-01-20 18:51:49 +00:00 committed by Benjamin Gruenbaum
parent 4a782e12a8
commit fe1be39b28

View File

@ -148,7 +148,18 @@ added: v0.1.90
* Returns: {ChildProcess}
Spawns a shell then executes the `command` within that shell, buffering any
generated output.
generated output. The `command` string passed to the exec function is processed
directly by the shell and special characters (vary based on
[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');
//Double quotes are used so that the space in the path is not interpreted as
//multiple arguments
exec('echo "The \\$HOME variable is $HOME"');
//The $HOME variable is escaped in the first instance, but not in the second
```
**Note: Never pass unsanitised user input to this function. Any input
containing shell metacharacters may be used to trigger arbitrary command