Skip to content

Commit 4c4212d

Browse files
committed
refactor(launch-editor): use powershell instead of wmic
1 parent 8327428 commit 4c4212d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/launch-editor.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,22 @@ function guessEditor() {
211211
}
212212
}
213213
else if (process.platform === "win32") {
214-
// Some processes need elevated rights to get its executable path.
215-
// Just filter them out upfront. This also saves 10-20ms on the command.
216214
const output = child_process
217-
.execSync(
218-
"wmic process where \"executablepath is not null\" get executablepath",
219-
{ stdio: ["pipe", "pipe", "ignore"] },
220-
)
215+
.execSync("powershell -Command \"Get-Process | Select-Object Path\"", {
216+
stdio: ["pipe", "pipe", "ignore"],
217+
})
221218
.toString()
222219
const runningProcesses = output.split("\r\n")
223220
for (let i = 0; i < runningProcesses.length; i++) {
224-
const processPath = runningProcesses[i].trim()
225-
const processName = path.basename(processPath)
226-
if (COMMON_EDITORS_WIN.indexOf(processName) !== -1)
227-
return [processPath]
221+
// `Get-Process` sometimes returns empty lines
222+
if (!runningProcesses[i])
223+
continue
224+
225+
const fullProcessPath = runningProcesses[i].trim()
226+
const shortProcessName = path.basename(fullProcessPath)
227+
228+
if (COMMON_EDITORS_WIN.indexOf(shortProcessName) !== -1)
229+
return [fullProcessPath]
228230
}
229231
}
230232
else if (process.platform === "linux") {

0 commit comments

Comments
 (0)