Skip to content

Commit

Permalink
bug: Fix for Windows' drain error on process.exit (Issue 3584)
Browse files Browse the repository at this point in the history
Output to stderr or stdout is not always completly written if
you exit the process. Issue happens only on Windows using pipes.

Issue nodejs/node-v0.x-archive#3584 will be fixed in
node.js 0.12.
  • Loading branch information
agebert committed Jan 30, 2015
1 parent e3776b6 commit 9ac7558
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'use strict';

var conf = require('./conf.js'),
exit = require('exit'),
configurationPath,
isRead;

Expand All @@ -14,7 +15,7 @@ if( process.argv.length < 3
console.log( 'Usage: node ' + process.argv[1] + ' [-u] <configuration path>\n\n' +
'-u: Update configuration. Configuration is read from stdin.\n' +
'Default is to display the configuration at stdout.');
process.exit(1);
exit(1);
}

isRead = process.argv.length === 3;
Expand All @@ -25,7 +26,7 @@ conf.initOnlyFiles(configurationPath);
if( isRead) {
var value = conf.get();
process.stdout.write(JSON.stringify(value, null, 2));
process.exit();
exit(0);
} else {
process.stdin.setEncoding('utf8');

Expand All @@ -38,14 +39,14 @@ if( isRead) {
if(e instanceof SyntaxError) {
process.stderr.write('Invalid JSON: ');
process.stderr.write(e.message);
process.exit(1);
exit(1);
} else {
process.stderr.write(e);
process.exit(2);
exit(2);
}
}
conf.save(function () {
process.exit();
exit();
})
}
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dependencies": {
"nconf": "^0.6.9",
"fs-extra": "^0.9.1",
"async": "^0.9.0"
"async": "^0.9.0",
"exit": "^0.1.2"
},
"devDependencies": {
"nodeunit": "^0.9.0"
Expand Down

0 comments on commit 9ac7558

Please sign in to comment.