forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: nodejs#1197
- Loading branch information
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const spawn = require('child_process').spawn; | ||
|
||
// spawn a node child process in "interactive" mode (force the repl) and eval | ||
const cp = spawn(process.execPath, ['-i', '-e', 'console.log("42")']); | ||
var gotToEnd = false; | ||
const timeoutId = setTimeout(function() { | ||
throw new Error('timeout!'); | ||
}, common.platformTimeout(1000)); // give node + the repl 1 second to boot up | ||
|
||
cp.stdout.setEncoding('utf8'); | ||
|
||
var output = ''; | ||
cp.stdout.on('data', function(b) { | ||
output += b; | ||
if (output === '> 42\n') { | ||
clearTimeout(timeoutId); | ||
gotToEnd = true; | ||
cp.kill(); | ||
} | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert(gotToEnd); | ||
}); |