summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRyan Graham <r.m.graham@gmail.com>2014-07-07 16:38:05 -0700
committerFedor Indutny <fedor@indutny.com>2014-07-10 15:20:33 +0300
commit9452ea2ef5bbaf4c0b03764c53899d97d0f210f3 (patch)
tree04059bc8a6dcf975b346892974850d8099738624 /doc
parenta7b14f7a89e7d319d193a6be179bb13b376cc031 (diff)
downloadandroid-node-v8-9452ea2ef5bbaf4c0b03764c53899d97d0f210f3.tar.gz
android-node-v8-9452ea2ef5bbaf4c0b03764c53899d97d0f210f3.tar.bz2
android-node-v8-9452ea2ef5bbaf4c0b03764c53899d97d0f210f3.zip
doc: re-org child_process into async/sync
Cleaner separation between the traditional non-blocking functions and the new blocking variants. Signed-off-by: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/child_process.markdown46
1 files changed, 30 insertions, 16 deletions
diff --git a/doc/api/child_process.markdown b/doc/api/child_process.markdown
index 2705209312..5e6ecfb9c9 100644
--- a/doc/api/child_process.markdown
+++ b/doc/api/child_process.markdown
@@ -8,11 +8,15 @@ Node provides a tri-directional `popen(3)` facility through the
It is possible to stream data through a child's `stdin`, `stdout`, and
`stderr` in a fully non-blocking way. (Note that some programs use
line-buffered I/O internally. That doesn't affect node.js but it means
-data you send to the child process is not immediately consumed.)
+data you send to the child process may not be immediately consumed.)
To create a child process use `require('child_process').spawn()` or
`require('child_process').fork()`. The semantics of each are slightly
-different, and explained below.
+different, and explained [below](#child_process_asynchronous_process_creation).
+
+For scripting purposes you may find the
+[synchronous counterparts](#child_process_synchronous_process_creation) more
+convenient.
## Class: ChildProcess
@@ -24,7 +28,8 @@ streams of the parent process, or they may be separate stream objects
which can be piped to and from.
The ChildProcess class is not intended to be used directly. Use the
-`spawn()` or `fork()` methods to create a Child Process instance.
+`spawn()`, `exec()`, `execFile()`, or `fork()` methods to create a Child
+Process instance.
### Event: 'error'
@@ -293,7 +298,12 @@ of being received, most likely immediately.
Note that you can also call `process.disconnect()` in the child process when the
child process has any open IPC channels with the parent (i.e `fork()`).
-## child_process.spawn(command, [args], [options])
+## Asynchronous Process Creation
+
+These methods follow the common async programming patterns (accepting a
+callback or returning an EventEmitter).
+
+### child_process.spawn(command, [args], [options])
* `command` {String} The command to run
* `args` {Array} List of string arguments
@@ -309,7 +319,7 @@ child process has any open IPC channels with the parent (i.e `fork()`).
Launches a new process with the given `command`, with command line arguments in `args`.
If omitted, `args` defaults to an empty Array.
-The third argument is used to specify additional options, which defaults to:
+The third argument is used to specify additional options, with these defaults:
{ cwd: undefined,
env: process.env
@@ -381,11 +391,6 @@ Example of checking for failed exec:
console.log('Failed to start child process.');
});
-Note that if spawn receives an empty options object, it will result in
-spawning the process with an empty environment rather than using
-`process.env`. This due to backwards compatibility issues with a deprecated
-API.
-
The 'stdio' option to `child_process.spawn()` is an array where each
index corresponds to a fd in the child. The value is one of the following:
@@ -468,7 +473,7 @@ inherited, the child will remain attached to the controlling terminal.
See also: `child_process.exec()` and `child_process.fork()`
-## child_process.exec(command, [options], callback)
+### child_process.exec(command, [options], callback)
* `command` {String} The command to run, with space-separated arguments
* `options` {Object}
@@ -526,7 +531,7 @@ amount of data allowed on stdout or stderr - if this value is exceeded then
the child process is killed.
-## child_process.execFile(file, [args], [options], [callback])
+### child_process.execFile(file, [args], [options], [callback])
* `file` {String} The filename of the program to run
* `args` {Array} List of string arguments
@@ -550,7 +555,7 @@ subshell but rather the specified file directly. This makes it slightly
leaner than `child_process.exec`. It has the same options.
-## child_process.fork(modulePath, [args], [options])
+### child_process.fork(modulePath, [args], [options])
* `modulePath` {String} The module to run in the child
* `args` {Array} List of string arguments
@@ -584,7 +589,16 @@ done with care and by default will talk over the fd represented an
environmental variable `NODE_CHANNEL_FD` on the child process. The input and
output on this fd is expected to be line delimited JSON objects.
-## child_process.spawnSync(command, [args], [options])
+## Synchronous Process Creation
+
+These methods are **synchronous**, meaning they **WILL** block the event loop,
+pausing execution of your code until the spawned process exits.
+
+Blocking calls like these are mostly useful for simplifying general purpose
+scripting tasks and for simplifying the loading/processing of application
+configuration at startup.
+
+### child_process.spawnSync(command, [args], [options])
* `command` {String} The command to run
* `args` {Array} List of string arguments
@@ -615,7 +629,7 @@ until the process has completely exited. That is to say, if the process handles
the `SIGTERM` signal and doesn't exit, your process will wait until the child
process has exited.
-## child_process.execFileSync(command, [args], [options])
+### child_process.execFileSync(command, [args], [options])
* `command` {String} The command to run
* `args` {Array} List of string arguments
@@ -646,7 +660,7 @@ throw. The `Error` object will contain the entire result from
[`child_process.spawnSync`](#child_process_child_process_spawnsync_command_args_options)
-## child_process.execSync(command, [options])
+### child_process.execSync(command, [options])
* `command` {String} The command to run
* `options` {Object}