First of all, it's a bad idea to extend native prototypes. Some third party modules can rely on that, etc, etc. So instead of `child.kill` you could write external function and call it as `kill(child)`.
Ohh... that sentence looks weird... poor children.
There is also a possibility to capture require(...) calls and replace the entire child_process module with something you control. You can look for what `mockery` module is doing.
09.08.2014, 06:32, "Nicholas Sotiros" <[email protected]>:
I would like to make it so that ChildProcess.prototype.kill() reaps all children and is platform independent. However I cannot seem to find access to the ChildProcess constructor without actually instantiating it. Require('child_process') gives only helper constructors like spawn and exec, not actual constructors. Is there something I am missing here?--cp = require('child_process')
switch (process.platform) {
case 'win32':
ChildProcess = cp.spawn('cmd').constructor;
ChildProcess.prototype.kill = function() {
cp.exec("taskkill /F /T /PID " + this.pid, function(error, stdout, stderr) {
if (error) {
throw error;
}
});
};
spawn = function(command, commandline) {
cp.spawn('cmd', ['/C', command].concat(commandline));
};
break;
default:
ChildProcess = cp.spawn('ls').constructor;
ChildProcess.prototype.kill = function() {
cp.exec("kill -TERM -" + this.pid, function(error, stdout, stderr) {
if (error) {
throw error;
}
});
spawn = function(command, commandline) {
cp.spawn(command, commandline, {
detach: true
});
};
};--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/3ba5d6a6-cabf-4270-ae4b-52b9094b343c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/2765591407705954%40web27m.yandex.ru.
For more options, visit https://groups.google.com/d/optout.
