From ad81a04fd73109c74f7f4118f43a74a65dd18559 Mon Sep 17 00:00:00 2001 From: Levin Rickert Date: Mon, 15 Jan 2018 21:26:11 +0100 Subject: [PATCH] Use wmic to get process list on Windows --- packages/react-dev-utils/launchEditor.js | 25 ++++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/react-dev-utils/launchEditor.js b/packages/react-dev-utils/launchEditor.js index cf190b08619..933fc1d4d30 100644 --- a/packages/react-dev-utils/launchEditor.js +++ b/packages/react-dev-utils/launchEditor.js @@ -56,8 +56,7 @@ const COMMON_EDITORS_OSX = { '/Applications/RubyMine.app/Contents/MacOS/rubymine', '/Applications/WebStorm.app/Contents/MacOS/webstorm': '/Applications/WebStorm.app/Contents/MacOS/webstorm', - '/Applications/MacVim.app/Contents/MacOS/MacVim': - 'mvim', + '/Applications/MacVim.app/Contents/MacOS/MacVim': 'mvim', }; const COMMON_EDITORS_LINUX = { @@ -188,23 +187,19 @@ function guessEditor() { } } } else if (process.platform === 'win32') { + // Some processes need elevated rights to get its executable path. + // Just filter them out upfront. This also saves 10-20ms on the command. const output = child_process - .execSync('powershell -Command "Get-Process | Select-Object Path"', { - stdio: ['pipe', 'pipe', 'ignore'], - }) + .execSync( + 'wmic process where "executablepath is not null" get executablepath' + ) .toString(); const runningProcesses = output.split('\r\n'); for (let i = 0; i < runningProcesses.length; i++) { - // `Get-Process` sometimes returns empty lines - if (!runningProcesses[i]) { - continue; - } - - const fullProcessPath = runningProcesses[i].trim(); - const shortProcessName = path.basename(fullProcessPath); - - if (COMMON_EDITORS_WIN.indexOf(shortProcessName) !== -1) { - return [fullProcessPath]; + const processPath = runningProcesses[i].trim(); + const processName = path.basename(processPath); + if (COMMON_EDITORS_WIN.indexOf(processName) !== -1) { + return [processPath]; } } } else if (process.platform === 'linux') {