-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command::spawn has weird rules for finding binaries on Windows #37519
Comments
Personally I'd much rather we didn't have this hack and just accepted that Windows and Unix are different and document their differences. |
@ollie27 these all sound like bugs to me rather than weird behavior. Removing this behavior is not an option as the are plenty of programs currently relying on this behavior. Would be great to fix the issues, however! |
It would definitely be nicer if |
Another issue is that |
I just found in #50870 (comment) that it's consistent with |
I just found a documentation about how file extensions work in Windows, and it might help since CMD finds the application to open a file with |
By the way @luser, after reading through this thread I found that in the interim the |
E.g. launching VSCode doesn't work: Command::new("code").spawn().unwrap(); // Error { kind: NotFound, message: "program not found" } CMD and PowerShell launch In Rust you need to specify extension |
If some of you weren't aware, it might help to know that the Hope that helps others like it helped me! |
This thread was about buggy behaviour that has since been fixed (aside from improving the documentation). The fact that I opened #94743 to discuss running scripts, etc, from |
Perhaps helpful - https://github.com/cli/safeexec |
Adding more rustdocs to clarify this sounds like a good idea. Maybe someone who regularly works with this on Windows can put up a PR? |
The offending code is here which is apparently to have it search the child's
%Path%
for the binary to fix #15149. It has a few issues though.Command::new("foo.exe").spawn()
andCommand::new("foo.exe").env("Thing", "").spawn()
uses different rules for finding the binary which seems unexpected..exe
. This meansCommand::new("foo.bar").env("Thing", "").spawn()
attempts to launchfoo.exe
first.Command::new("foo.bar").spawn()
correctly tries to launchfoo.bar
asCreateProcess
will not replace the extension.%Path%
. For exampleCommand::new(r"C:\foo.bar").env("Thing", "").spawn()
looks forC:\foo.exe
several times..to_str().unwrap()
means itpanic!
s if the program name is not valid Unicode.std::process::Command
).An easy way to fix this is to just remove the hack so we just rely on the behaviour of
CreateProcess
on Windows which is a least documented. The behaviour is already very different between Windows and Linux and we should probably just accept that in order to get reliable results cross-platform it's best to use absolute paths.The text was updated successfully, but these errors were encountered: