Created
November 20, 2012 10:30
-
-
Save pghalliday/4117163 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
Can you Help me on this ?
session.on('exec', function (accept, reject, info) {
console.log('Client wants to execute: ' + inspect(info.command));
var stream = accept();
When I manually type the first command 'XXXCLI ip_address' in my command prompt and press enter,I will get a output "Connected to CLI...." .Once I get this connection successful, I need to execute my second command i.e "Lmc sample" which will load the master config and I will get the output as "Message sent..", third command will execute a script,will get output as "Message sent.." .This is what happens when I enter these commands manually in cmd prompt and execute.
What is happening is once I execute my first command i.e "XXXCLI 10.21.254.12" manually in cmd, The path where we actually execute the commands i.e( C:\users\CLI>) will not be visible. This happens because now it got connected with the above mentioned ip (10.21.254.12) .And Only after connecting to this ip ,I can able to execute my other commands.i.e command to load master config ,cmd to execute script etc.
So I want to execute my first command and get its stream in a variable and execute rest of the commands inside the stream created by first command Thanks!