Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wmic to get process list on Windows #3808

Merged
merged 1 commit into from
Jan 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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