Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Allow calling fork() without args or options
Browse files Browse the repository at this point in the history
Closes GH-2424
  • Loading branch information
AndreasMadsen authored and piscisaureus committed Jan 17, 2012
1 parent 21dd53f commit 7088487
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/api/child_processes.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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, arguments, options)
### child_process.fork(modulePath, [arguments], [options])

This is a special case of the `spawn()` functionality for spawning Node
processes. In addition to having all the methods in a normal ChildProcess
Expand Down
16 changes: 13 additions & 3 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,23 @@ function setupChannel(target, channel) {

function nop() { }

exports.fork = function(modulePath /*, args, options*/) {

exports.fork = function(modulePath, args, options) {
if (!options) options = {};
// Get options and args arguments.
var options, args;
if (Array.isArray(arguments[1])) {
args = arguments[1];
options = arguments[2] || {};
} else {
args = [];
options = arguments[1] || {};
}

args = args ? args.slice(0) : [];
// Copy args and add modulePath
args = args.slice(0);
args.unshift(modulePath);

// Don't allow stdinStream and customFds since a stdin channel will be used
if (options.stdinStream) {
throw new Error('stdinStream not allowed for fork()');
}
Expand Down

0 comments on commit 7088487

Please sign in to comment.