Skip to content

Instantly share code, notes, and snippets.

@JFKingsley
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JFKingsley/9822932 to your computer and use it in GitHub Desktop.
Save JFKingsley/9822932 to your computer and use it in GitHub Desktop.
var parent = function() {
var spawn = require('child_process').spawn;
var child = spawn(config('php_command'), ['-S', config('php_serve_url')]);
var stdout = '';
var stderr = '';
child.stdout.on('data', function(buf) {
console.log('[STR] stdout "%s"', String(buf));
stdout += buf;
});
child.stderr.on('data', function(buf) {
console.log('[STR] stderr "%s"', String(buf));
stderr += buf;
});
child.on('close', function(code) {
console.log('[END] code', code);
console.log('[END] stdout "%s"', stdout);
console.log('[END] stderr "%s"', stderr);
});
};
var child = function() {
var code = Number(process.argv[2]);
process.stdout.write('stdout');
process.stderr.write('stderr');
exit(code);
};
// This appears to fix the problem:
// https://gist.github.com/3427357
function exit(exitCode) {
if (process.stdout._pendingWriteReqs || process.stderr._pendingWriteReqs) {
process.nextTick(function() {
exit(exitCode);
});
} else {
process.exit(exitCode);
}
}
if (process.argv[2]) {
child();
} else {
parent();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment