Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

check if stdin is a tty and run the stdin stream if not

  • Loading branch information...
commit 6a23448c0776cd2cea4e37f3deadc238dab9a8cb 1 parent 5f5e30e
@substack authored
Showing with 20 additions and 2 deletions.
  1. +19 −1 bin/cmd.js
  2. +1 −1  package.json
View
20 bin/cmd.js
@@ -61,7 +61,7 @@ if (argv.r || argv.run || argv._[0]) {
return;
}
-if (true || argv.i || argv.interactive) {
+if (process.stdin.isTTY || argv.i || argv.interactive) {
var ctx = {
require : require,
console : console,
@@ -72,6 +72,24 @@ if (true || argv.i || argv.interactive) {
number.run(n, cb);
});
}
+else {
+ var data = '';
+ var ctx = {
+ require : function (name) {
+ if (name === 'number-script') return number
+ else return require(name)
+ },
+ console : console,
+ process : process,
+ };
+ process.stdin.on('data', function (buf) { data += buf });
+ process.stdin.on('end', function () {
+ number.run(data, ctx, function (err, res) {
+ if (err) console.error(err);
+ });
+ });
+ process.stdin.resume();
+}
function readFile (file, cb) {
if (file === true || file === '-') {
View
2  package.json
@@ -1,6 +1,6 @@
{
"name" : "number-script",
- "version" : "0.0.2",
+ "version" : "0.0.3",
"description" : "Ordinal JavaScript",
"main" : "index.js",
"bin" : {
Please sign in to comment.
Something went wrong with that request. Please try again.