Using shell/cmd commands to kill browser tasks
This commit is contained in:
parent
cbf35cae0f
commit
b72094d740
@ -66,28 +66,29 @@ WebBrowser.prototype = {
|
|||||||
var proc = spawn(this.path, args);
|
var proc = spawn(this.path, args);
|
||||||
proc.on('exit', function (code) {
|
proc.on('exit', function (code) {
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
// trying to wait for process to shutdown (for Windows sake)
|
this.cleanup(this.callback && this.callback.bind(null, code));
|
||||||
setTimeout(function () {
|
|
||||||
this.cleanup();
|
|
||||||
if (this.callback) {
|
|
||||||
this.callback.call(null, code);
|
|
||||||
}
|
|
||||||
}.bind(this), 500);
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
return proc;
|
return proc;
|
||||||
},
|
},
|
||||||
cleanup: function () {
|
cleanup: function (callback) {
|
||||||
try {
|
try {
|
||||||
testUtils.removeDirSync(this.tmpDir);
|
testUtils.removeDirSync(this.tmpDir);
|
||||||
|
this.process = null;
|
||||||
|
callback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Unable to cleanup after the process: ' + e);
|
console.error('Unable to cleanup after the process: ' + e);
|
||||||
try {
|
try {
|
||||||
if (this.process) {
|
if (this.process) {
|
||||||
this.process.kill('SIGKILL');
|
var pid = this.process.pid;
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
// kill does not really work on windows
|
||||||
|
spawn('taskkill', ['-F', '-PID', pid]).on('exit', callback);
|
||||||
|
} else {
|
||||||
|
spawn('kill', ['-s', 'SIGKILL', pid]).on('exit', callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
this.process = null;
|
|
||||||
},
|
},
|
||||||
stop: function (callback) {
|
stop: function (callback) {
|
||||||
if (this.finished) {
|
if (this.finished) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user