From f6ac07087ae4c4b12720d477325991f8cddf96e9 Mon Sep 17 00:00:00 2001 From: Zhuofeng Wang Date: Thu, 4 Jan 2024 20:27:09 +0800 Subject: [PATCH] fix: program location in wsl (#309) The absolute path of cmd.exe is a more stable choice in wsl. --- app/lib/util/opener.js | 9 ++++++++- src/util/opener.ts | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/lib/util/opener.js b/app/lib/util/opener.js index e033678d..adfb652b 100644 --- a/app/lib/util/opener.js +++ b/app/lib/util/opener.js @@ -8,6 +8,7 @@ const child_process_1 = tslib_1.__importDefault(require("child_process")); const os_1 = tslib_1.__importDefault(require("os")); module.exports = function opener(args, tool) { let platform = process.platform; + let is_wsl = false; args = [].concat(args); // Attempt to detect Windows Subystem for Linux (WSL). // WSL itself as Linux (which works in most cases), but in @@ -16,12 +17,18 @@ module.exports = function opener(args, tool) { // whereas using xdg-open does not, since there is no X Windows in WSL. if (platform === 'linux' && os_1.default.release().toLowerCase().indexOf('microsoft') !== -1) { platform = 'win32'; + is_wsl = true; } // http://stackoverflow.com/q/1480971/3191, but see below for Windows. let command; switch (platform) { case 'win32': { - command = 'cmd.exe'; + if (is_wsl) { + command = '/mnt/c/Windows/System32/cmd.exe'; + } + else { + command = 'cmd.exe'; + } if (tool) { args.unshift(tool); } diff --git a/src/util/opener.ts b/src/util/opener.ts index e0fd2ff5..860fb794 100644 --- a/src/util/opener.ts +++ b/src/util/opener.ts @@ -9,6 +9,7 @@ module.exports = function opener( tool: string | undefined ) { let platform = process.platform + let is_wsl = false args = [].concat(args) // Attempt to detect Windows Subystem for Linux (WSL). @@ -18,13 +19,18 @@ module.exports = function opener( // whereas using xdg-open does not, since there is no X Windows in WSL. if (platform === 'linux' && os.release().toLowerCase().indexOf('microsoft') !== -1) { platform = 'win32' + is_wsl = true } // http://stackoverflow.com/q/1480971/3191, but see below for Windows. let command switch (platform) { case 'win32': { - command = 'cmd.exe' + if (is_wsl) { + command = '/mnt/c/Windows/System32/cmd.exe' + } else { + command = 'cmd.exe' + } if (tool) { args.unshift(tool) }