-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathkill.js
More file actions
52 lines (43 loc) · 1.28 KB
/
kill.js
File metadata and controls
52 lines (43 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var exec = require('child_process').exec;
/**
* Kills a process by PID.
* @param pid Required. Process ID.
* @param callback Optional.
* @remarks Windows only
*/
exports.pid = function (pid, callback) {
if (!pid) throw new Error('pid is required');
if (!callback) callback = function () { };
exec('taskkill /t /f /pid ' + pid.toString(), function (err, stdout, stderr) {
if (err) {
callback({ msg: "unable to kill " + pid, err: err, stdout: stdout, stderr: stderr });
return;
}
callback();
});
};
/**
* Kills all the processes with the specified image name
* @param imageName Required. The name of the image (e.g. 'node.exe')
* @param callback Optional.
*/
exports.image = function (imageName, opts, callback) {
if (!imageName) throw new Error('imageName is required');
if (typeof opts === 'function') {
callback = opts;
opts = '';
}
if (!opts) {
opts = '';
}
if (!callback) callback = function () { };
var cmd = ('taskkill /t /f /im ' + imageName + ' ' + opts).trim();
console.log('cmd:', cmd);
exec(cmd, function (err, stdout, stderr) {
if (err) {
callback({ msg: "unable to kill " + imageName, err: err, stdout: stdout, stderr: stderr });
return;
}
callback();
});
}