Skip to content

Commit fe1be39

Browse files
codeman869Benjamin Gruenbaum
authored and
Benjamin Gruenbaum
committed
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: #10921 Fixes: #6803 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 4a782e1 commit fe1be39

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

doc/api/child_process.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,18 @@ added: v0.1.90
148148
* Returns: {ChildProcess}
149149

150150
Spawns a shell then executes the `command` within that shell, buffering any
151-
generated output.
151+
generated output. The `command` string passed to the exec function is processed
152+
directly by the shell and special characters (vary based on
153+
[shell](https://en.wikipedia.org/wiki/List_of_command-line_interpreters))
154+
need to be dealt with accordingly:
155+
```js
156+
exec('"/path/to/test file/test.sh" arg1 arg2');
157+
//Double quotes are used so that the space in the path is not interpreted as
158+
//multiple arguments
159+
160+
exec('echo "The \\$HOME variable is $HOME"');
161+
//The $HOME variable is escaped in the first instance, but not in the second
162+
```
152163

153164
**Note: Never pass unsanitised user input to this function. Any input
154165
containing shell metacharacters may be used to trigger arbitrary command

0 commit comments

Comments
 (0)