Skip to content

Commit 6f275f9

Browse files
branchseerclaude
andcommitted
fix: preserve Windows system env vars for cmd.exe to work
cmd.exe needs system environment variables to function correctly. Instead of clearing all env vars on Windows, only clear them on Unix. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e19bdb7 commit 6f275f9

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • crates/vite_task_bin/tests/test_snapshots

crates/vite_task_bin/tests/test_snapshots/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,21 @@ fn run_case(runtime: &Runtime, tmpdir: &AbsolutePath, fixture_path: &Path) {
173173
let mut e2e_outputs = String::new();
174174
for step in e2e.steps {
175175
let mut cmd = if cfg!(windows) {
176-
// Use PowerShell on Windows for better argument handling
177-
let mut cmd = Command::new("powershell.exe");
178-
cmd.args(["-NoProfile", "-NonInteractive", "-Command"]);
176+
let mut cmd = Command::new("cmd.exe");
177+
// https://github.com/nodejs/node/blob/dbd24b165128affb7468ca42f69edaf7e0d85a9a/lib/child_process.js#L633
178+
cmd.args(["/d", "/s", "/c"]);
179179
cmd
180180
} else {
181181
let mut cmd = Command::new("sh");
182182
cmd.args(["-c"]);
183183
cmd
184184
};
185+
// On Windows, env_clear() would break cmd.exe, so only set PATH
186+
// On Unix, clear all envs for reproducibility
187+
if !cfg!(windows) {
188+
cmd.env_clear();
189+
}
185190
cmd.arg(step.as_str())
186-
.env_clear()
187191
.env("PATH", &e2e_env_path)
188192
.env("NO_COLOR", "1")
189193
.current_dir(e2e_stage_path.join(&e2e.cwd));

0 commit comments

Comments
 (0)