-
-
Save jhliberty/4c1a6ae23a90707e8953 to your computer and use it in GitHub Desktop.
node.js windows spawn with cmd /s /c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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