Skip to content
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
10 changes: 10 additions & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ exports.fork = function(modulePath /*, args, options*/) {

// Prepare arguments for fork:
execArgv = options.execArgv || process.execArgv;

if (execArgv === process.execArgv && process._eval != null) {
const index = execArgv.lastIndexOf(process._eval);
if (index > 0) {
// Remove the -e switch to avoid fork bombing ourselves.
execArgv = execArgv.slice();
execArgv.splice(index - 1, 2);
}
}

args = execArgv.concat([modulePath], args);

// Leave stdin open for the IPC channel. stdout and stderr should be the
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-cli-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (module.parent) {
var common = require('../common'),
assert = require('assert'),
child = require('child_process'),
path = require('path'),
nodejs = '"' + process.execPath + '"';


Expand Down Expand Up @@ -75,3 +76,11 @@ child.exec(nodejs + ' --use-strict -p process.execArgv',
function(status, stdout, stderr) {
assert.equal(stdout, "[ '--use-strict', '-p', 'process.execArgv' ]\n");
});

// Regression test for https://github.com/nodejs/node/issues/3574
const emptyFile = path.join(common.fixturesDir, 'empty.js');
child.exec(nodejs + ` -e 'require("child_process").fork("${emptyFile}")'`,
function(status, stdout, stderr) {
assert.equal(stdout, '');
assert.equal(stderr, '');
});