Skip to content

Commit

Permalink
doc: child_process example for special chars
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
codeman869 authored and Benjamin Gruenbaum committed Apr 16, 2017
1 parent 4a782e1 commit fe1be39
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe1be39

Please sign in to comment.