Allow script to be read from stdin
This commit is contained in:
parent
59f7232a30
commit
4a9f2de956
23
src/node.js
23
src/node.js
@ -80,9 +80,28 @@
|
|||||||
console.log(rv);
|
console.log(rv);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// REPL
|
var binding = process.binding('stdio');
|
||||||
|
var fd = binding.openStdin();
|
||||||
var Module = NativeModule.require('module');
|
var Module = NativeModule.require('module');
|
||||||
Module.requireRepl().start();
|
|
||||||
|
if (NativeModule.require('tty').isatty(fd)) {
|
||||||
|
// REPL
|
||||||
|
Module.requireRepl().start();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Read all of stdin - execute it.
|
||||||
|
process.stdin.resume();
|
||||||
|
process.stdin.setEncoding('utf8');
|
||||||
|
|
||||||
|
var code = '';
|
||||||
|
process.stdin.on('data', function(d) {
|
||||||
|
code += d;
|
||||||
|
});
|
||||||
|
|
||||||
|
process.stdin.on('end', function() {
|
||||||
|
new Module()._compile(code, '[stdin]');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user