Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4ecd996

Browse filesBrowse files
Trottevanlucas
authored andcommitted
src: allow combination of -i and -e cli flags
If both -i and -e flags are specified, do not ignore the -i. Instead, launch the interactive REPL and start by evaluating the passed string. Fixes: #1197 PR-URL: #5655 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 8c4c84f commit 4ecd996
Copy full SHA for 4ecd996

File tree

Expand file treeCollapse file tree

2 files changed

+35
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-2
lines changed
Open diff view settings
Collapse file

‎src/node.js‎

Copy file name to clipboardExpand all lines: src/node.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@
8888
delete process.env.NODE_UNIQUE_ID;
8989
}
9090

91-
if (process._eval != null) {
92-
// User passed '-e' or '--eval' arguments to Node.
91+
if (process._eval != null && !process._forceRepl) {
92+
// User passed '-e' or '--eval' arguments to Node without '-i' or
93+
// '--interactive'
9394
startup.preloadModules();
9495
evalScript('[eval]');
9596
} else if (process.argv[1]) {
@@ -161,6 +162,11 @@
161162
process.exit();
162163
});
163164
});
165+
166+
if (process._eval != null) {
167+
// User passed '-e' or '--eval'
168+
evalScript('[eval]');
169+
}
164170
} else {
165171
// Read all of stdin - execute it.
166172
process.stdin.setEncoding('utf8');
Collapse file
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const spawn = require('child_process').spawn;
5+
6+
// spawn a node child process in "interactive" mode (force the repl) and eval
7+
const cp = spawn(process.execPath, ['-i', '-e', 'console.log("42")']);
8+
var gotToEnd = false;
9+
const timeoutId = setTimeout(function() {
10+
throw new Error('timeout!');
11+
}, common.platformTimeout(1000)); // give node + the repl 1 second to boot up
12+
13+
cp.stdout.setEncoding('utf8');
14+
15+
var output = '';
16+
cp.stdout.on('data', function(b) {
17+
output += b;
18+
if (output === '> 42\n') {
19+
clearTimeout(timeoutId);
20+
gotToEnd = true;
21+
cp.kill();
22+
}
23+
});
24+
25+
process.on('exit', function() {
26+
assert(gotToEnd);
27+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.