Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: set shell to false in fork() #15352

Merged
merged 2 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ output on this fd is expected to be line delimited JSON objects.
*Note*: Unlike the fork(2) POSIX system call, `child_process.fork()` does
not clone the current process.

*Note*: The `shell` option available in [`child_process.spawn()`][] is not
supported by `child_process.fork()` and will be ignored if set.

### child_process.spawn(command[, args][, options])
<!-- YAML
added: v0.1.90
Expand Down
1 change: 1 addition & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ exports.fork = function(modulePath /*, args, options*/) {
}

options.execPath = options.execPath || process.execPath;
options.shell = false;

return spawn(options.execPath, args, options);
};
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-child-process-fork-no-shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
// This test verifies that the shell option is not supported by fork().
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const expected = common.isWindows ? '%foo%' : '$foo';

if (process.argv[2] === undefined) {
const child = cp.fork(__filename, [expected], {
shell: true,
env: { foo: 'bar' }
});

child.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
}));
} else {
assert.strictEqual(process.argv[2], expected);
}