提交 589b933f 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

kill ztf process by electron

上级 569f860a
import path from 'path'; import path from 'path';
import cp, {spawn} from 'child_process'; import cp, {exec, spawn} from 'child_process';
import os from 'os'; import os from 'os';
import {app} from 'electron'; import {app} from 'electron';
import express from 'express'; import express from 'express';
...@@ -269,29 +269,38 @@ export function killZtfServer() { ...@@ -269,29 +269,38 @@ export function killZtfServer() {
logInfo(`>> is windows`); logInfo(`>> is windows`);
const cmd = 'WMIC path win32_process where "Commandline like \'%%' + uuid + '%%\'" get Processid,Caption'; const cmd = 'WMIC path win32_process where "Commandline like \'%%' + uuid + '%%\'" get Processid,Caption';
logInfo(`list process cmd : ${cmd}`); let msg = `list process cmd : ${cmd}`
console.log(msg);
logInfo(msg);
const cp = require('child_process'); const cp = require('child_process');
cp.exec(cmd, function (error, stdout, stderr) { const stdout = cp.execSync(cmd).toString().trim()
// console.log('stdout: ' + stdout + '; stderr: ' + stderr + '; error: ' + error + '.'); msg = `exec ${cmd}, stdout: ${stdout}`
const lines = stdout.split('\n') console.log(msg);
lines.forEach(function(line){ logInfo(msg)
line = line.trim()
console.log('<' + line + '>')
const columns = line.split(/\s/)
if (columns.length > 2) { const lines = stdout.split('\n')
const pid = columns[2].trim() lines.forEach(function(line){
console.log(`pid=${pid}`); line = line.trim()
console.log(`<${line}>`)
logInfo(`<${line}>`)
const columns = line.split(/\s/)
const cpKill = require('child_process'); if (columns.length > 2) {
const pid = columns[2].trim()
console.log(`pid=${pid}`);
logInfo(`pid=${pid}`)
if (pid && parseInt(pid, 10) === pid) {
const killCmd = `taskkill /F /pid ${pid}` const killCmd = `taskkill /F /pid ${pid}`
logInfo(`list cmd : ${killCmd}`);
cpKill.exec(killCmd, function (error, stdout, stderr) { const cp = require('child_process');
console.log('stdout: ' + stdout + '; stderr: ' + stderr + '; error: ' + error + '.'); const stdout = cp.execSync(killCmd).toString().trim()
}); msg = `exec ${cmd}, stdout: ${stdout}`
console.log(msg);
logInfo(msg)
} }
}); }
}); });
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册