fix: keep cmd.exe off the terminal under WSL

Reading the Windows variables through cmd.exe let it consume the answer typed at the first prompt: a WSL run exited 0 with nothing installed.
This commit is contained in:
Abdessamad Derraz committed 2026-10-19 05:15:52 +02:00
1 parent 3bb178bb74
commit f19dcba545
4 files changed
+9 -4

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ param(
$ErrorActionPreference = "Stop"
$defaultInstallUrl = "https://raw.githubusercontent.com/Abdess/retrobios/main/install.py"
$defaultInstallSha256 = "12b0c9b711955a664941529f4fef36a55799472d9788d43ab1988a15d31ce452"
$defaultInstallSha256 = "7e74935ae51bf8b0076f637bc640b33f0ca774bec065df56080a0321fa292820"
$maximumInstallerBytes = 2MB
$installerExit = 0
$installer = if ($PSScriptRoot) { Join-Path $PSScriptRoot "install.py" } else { $null }
+3 -1
View File
@@ -467,9 +467,11 @@ def _enter_wsl() -> None:
if os.environ.get(variable):
continue
try:
# No stdin: cmd.exe inherited the terminal and swallowed the
# answer typed at the first prompt.
result = subprocess.run(
["cmd.exe", "/c", f"echo %{variable}%"],
capture_output=True, text=True, timeout=10,
capture_output=True, text=True, timeout=10, stdin=subprocess.DEVNULL,
cwd="/mnt/c" if Path("/mnt/c").is_dir() else None,
)
except (OSError, subprocess.SubprocessError):
+1 -1
View File
@@ -18,7 +18,7 @@ esac
TEMP_INSTALLER=""
TEMP_DIRECTORY=""
DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/install.py"
DEFAULT_INSTALL_SHA256="12b0c9b711955a664941529f4fef36a55799472d9788d43ab1988a15d31ce452"
DEFAULT_INSTALL_SHA256="7e74935ae51bf8b0076f637bc640b33f0ca774bec065df56080a0321fa292820"
MAX_INSTALLER_BYTES=2097152
cleanup() {
+4 -1
View File
@@ -2812,7 +2812,10 @@ class WindowsSeenFromWsl(unittest.TestCase):
def test_the_windows_variables_are_read_through_cmd(self):
answers = {"USERPROFILE": "C:\\Users\\me", "APPDATA": "C:\\Users\\me\\AppData\\Roaming"}
def cmd(argv, **_kwargs):
def cmd(argv, **kwargs):
# cmd.exe must not read the terminal: it swallowed the answer
# typed at the first prompt.
self.assertIs(kwargs.get("stdin"), subprocess.DEVNULL)
name = argv[-1].split("%")[1]
return subprocess.CompletedProcess(argv, 0, answers.get(name, f"%{name}%") + "\r\n", "")