From 3e33f78235e4b0871f142c57d4c10b8c9f8d519a Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 24 Mar 2017 03:06:54 -0400 Subject: [PATCH] Add code to get process IDs for daemon on Windows --- app/main.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/main.js b/app/main.js index bcb617c96..d10d250ef 100644 --- a/app/main.js +++ b/app/main.js @@ -47,6 +47,19 @@ function openItem(fullPath) { child.unref(); } +function getPidsForProcessName(name) { + if (process.platform == 'windows') { + const tasklistOut = child_process.execSync('tasklist', + ['/fi', `Imagename eq ${name}.exe`, '/nh'], + {encoding: 'utf8'} + ).stdout; + return tasklistOut.match(/[^\n]+/g).map((line) => line.split(/\s+/)[1]); // Second column of every non-empty line + } else { + const pgrepOut = child_process.spawnSync('pgrep', ['-x', name], {encoding: 'utf8'}).stdout; + return pgrepOut.match(/\d+/g); + } +} + function createWindow () { win = new BrowserWindow({backgroundColor: '#155b4a'}) win.maximize() @@ -137,8 +150,7 @@ function launchDaemonIfNotRunning() { function forceKillAllDaemonsAndQuit() { console.log('Attempting to force kill any running lbrynet-daemon instances...'); - const fgrepOut = child_process.spawnSync('pgrep', ['-x', 'lbrynet-daemon'], {encoding: 'utf8'}).stdout; - const daemonPids = fgrepOut.match(/\d+/g); + const daemonPids = getPidsForProcessName('lbrynet-daemon'); if (!daemonPids) { console.log('No lbrynet-daemon found running.'); quitNow();