Skip to content

Commit 67af460

Browse files
levrikakstuhl
authored andcommitted
Use wmic to get process list on Windows (facebook#3808)
1 parent c3ec945 commit 67af460

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

packages/react-dev-utils/launchEditor.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ const COMMON_EDITORS_OSX = {
5656
'/Applications/RubyMine.app/Contents/MacOS/rubymine',
5757
'/Applications/WebStorm.app/Contents/MacOS/webstorm':
5858
'/Applications/WebStorm.app/Contents/MacOS/webstorm',
59-
'/Applications/MacVim.app/Contents/MacOS/MacVim':
60-
'mvim',
59+
'/Applications/MacVim.app/Contents/MacOS/MacVim': 'mvim',
6160
};
6261

6362
const COMMON_EDITORS_LINUX = {
@@ -188,23 +187,19 @@ function guessEditor() {
188187
}
189188
}
190189
} else if (process.platform === 'win32') {
190+
// Some processes need elevated rights to get its executable path.
191+
// Just filter them out upfront. This also saves 10-20ms on the command.
191192
const output = child_process
192-
.execSync('powershell -Command "Get-Process | Select-Object Path"', {
193-
stdio: ['pipe', 'pipe', 'ignore'],
194-
})
193+
.execSync(
194+
'wmic process where "executablepath is not null" get executablepath'
195+
)
195196
.toString();
196197
const runningProcesses = output.split('\r\n');
197198
for (let i = 0; i < runningProcesses.length; i++) {
198-
// `Get-Process` sometimes returns empty lines
199-
if (!runningProcesses[i]) {
200-
continue;
201-
}
202-
203-
const fullProcessPath = runningProcesses[i].trim();
204-
const shortProcessName = path.basename(fullProcessPath);
205-
206-
if (COMMON_EDITORS_WIN.indexOf(shortProcessName) !== -1) {
207-
return [fullProcessPath];
199+
const processPath = runningProcesses[i].trim();
200+
const processName = path.basename(processPath);
201+
if (COMMON_EDITORS_WIN.indexOf(processName) !== -1) {
202+
return [processPath];
208203
}
209204
}
210205
} else if (process.platform === 'linux') {

0 commit comments

Comments
 (0)