Permalink
Browse files

updated: Fixed bug where child might exit before STDOUT was drained.

  • Loading branch information...
1 parent 76cfc70 commit d74f81aaf7850a441107b7b2e22ab485eedef6b3 @gf3 committed May 1, 2010
Showing with 18 additions and 17 deletions.
  1. +18 −17 lib/shovel.js
View
@@ -2,31 +2,30 @@
// Gianni Chiappetta - gf3.ca - 2010
/* ------------------------------ INIT ------------------------------ */
-var sys = require("sys"),
- code = "",
- reserved = {
- // Node
- "require": null,
- "__filename": null,
- "__module": null,
- "module": null,
- // Local
- "code": null,
- "reserved": null,
- "run": null,
- "sys": null
- };
+var sys = require('sys')
+ , code = ''
+ , reserved =
+ { 'require': null
+ , '__filename': null
+ , '__module': null
+ , 'module': null
+ , 'code': null
+ , 'reserved': null
+ , 'run': null
+ , 'sys': null
+ }
+ ;
/* ------------------------------ Sandbox ------------------------------ */
// Generate list of reserved items
for (var i in GLOBAL) reserved[i] = null;
// Get code
var stdin = process.openStdin();
-stdin.addListener("data", function(data) {
+stdin.addListener('data', function(data) {
code += data;
});
-stdin.addListener("end", run);
+stdin.addListener('end', run);
// Run code
function run() {
@@ -39,7 +38,9 @@ function run() {
}
}).call(code);
+ process.stdout.addListener('drain', function() {
+ process.exit(0);
+ });
process.stdout.write(sys.inspect(output));
- process.exit(0);
}

0 comments on commit d74f81a

Please sign in to comment.