Skip to content

Instantly share code, notes, and snippets.

@jhliberty
Forked from pghalliday/1 test.js
Created February 16, 2016 09:36
Show Gist options
  • Select an option

  • Save jhliberty/4c1a6ae23a90707e8953 to your computer and use it in GitHub Desktop.

Select an option

Save jhliberty/4c1a6ae23a90707e8953 to your computer and use it in GitHub Desktop.
node.js windows spawn with cmd /s /c
var http = require('http');
var spawn = require('child_process').spawn;
var child = spawn(
'CMD', [
'/S',
'/C',
'node',
'./child.js'
]
);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
child.on('exit', function() {
http.get('http://localhost:8080', function(response) {
console.log('child did NOT die');
}).on('error', function(error) {
console.log('child did die');
});
});
setTimeout(function() {
http.get('http://localhost:8080', function(response) {
response.on('end', function() {
console.log('kill the child');
child.kill();
});
});
}, 2000);
var http = require('http');
var PORT = 8080;
var server = http.createServer(function(request, response) {
response.end();
});
server.listen(PORT, function() {
console.log('Listening on port ' + PORT);
});
V:\GitHub\node-ChildDaemon\test\Spikes\windows>node test.js
Listening on port 8080
kill the child
child did NOT die
*********
I can kill the process and children with ctrl-c at this point (although i expected it to kill the child and exit on it's own)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment