Skip to content

Commit

Permalink
Use wmic to get process list on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
levrik committed Jan 16, 2018
1 parent 19e0bb1 commit ad81a04
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions packages/react-dev-utils/launchEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit ad81a04

Please sign in to comment.