Skip to content

Commit 0009666

Browse files
jieyouxugitbot
authored and
gitbot
committed
Rollup merge of rust-lang#137673 - ChrisDenton:search-path-bug, r=dtolnay
Fix Windows `Command` search path bug Currently `Command::new` on Windows works differently depending on whether any environment variable is set. For example, ```rust // Searches for "myapp" in the application and system paths first (aka Windows native behaviour). Command::new("myapp").spawn(); // Search for "myapp" in `PATH` first Command::new("myapp").env("a", "b").spawn(); ``` This is a bug because the search path should only change if `PATH` is changed for the child (i.e. `.env("PATH", "...")`). This was discussed in a libs-api meeting where the exact semantics of `Command::new` was not decided but there seemed to be broad agreement that this particular thing is just a bug that can be fixed. r? libs-api
2 parents f255136 + ef22eba commit 0009666

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

std/src/sys/pal/windows/process.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ impl Command {
260260
needs_stdin: bool,
261261
proc_thread_attribute_list: Option<&ProcThreadAttributeList<'_>>,
262262
) -> io::Result<(Process, StdioPipes)> {
263+
let env_saw_path = self.env.have_changed_path();
263264
let maybe_env = self.env.capture_if_changed();
264265

265-
let child_paths = if let Some(env) = maybe_env.as_ref() {
266+
let child_paths = if env_saw_path && let Some(env) = maybe_env.as_ref() {
266267
env.get(&EnvKey::new("PATH")).map(|s| s.as_os_str())
267268
} else {
268269
None

0 commit comments

Comments
 (0)