Skip to content
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

[Windows] Command:spawn() only searches for .exe files #37380

Closed
afiune opened this issue Oct 24, 2016 · 3 comments
Closed

[Windows] Command:spawn() only searches for .exe files #37380

afiune opened this issue Oct 24, 2016 · 3 comments
Labels
O-windows Operating system: Windows

Comments

@afiune
Copy link

afiune commented Oct 24, 2016

Problem Description

In the Windows world you have .exe files but you can also have .bat files that can be executables in your PATH. The problem is that the implementation of the Command:spawn() in windows only checks for EXE (https://github.com/rust-lang/rust/blob/master/src/libstd/sys/windows/process.rs#L141) that means that if we have some BAT files that we would like to execute we currently can't.

Proposal Solution

Instead of checking just for EXE files we should check the PATHEXT Environment Variable to detect what available extensions we search for.

afiune pushed a commit to afiune/rust that referenced this issue Oct 25, 2016
Windows relies on path extensions to resolve commands, extensions
are found in the `PATHEXT` environment variable. We are adding a new
function called `Command:find_program()` that will return the `Path` of
the program found using the above env variable.

Closes rust-lang#37380

Signed-off-by: Salim Afiune <afiune@chef.io>
@sanxiyn sanxiyn added the O-windows Operating system: Windows label Oct 27, 2016
chef-delivery pushed a commit to chef-boneyard/delivery-cli that referenced this issue Nov 14, 2016
Since only `git.bat` is found in the `PATH` on Windows ChefDK installs:

https://github.com/chef/omnibus-software/blob/master/config/software/git-windows.rb#L50-L52

`delivery-cli` commands that shell out to `git` fail because Git can
not be found when Rust tries to find the executable to be spawned. This
is because Rust's Windows spawn command, when provided with a file path
without an extension, will only search for `.exe` files when searching the path:

rust-lang/rust#37380

https://github.com/rust-lang/rust/blob/master/src/libstd/sys/windows/process.rs#L141

https://github.com/rust-lang/rust/blob/master/src/libstd/sys/windows/env.rs#L18

This change adds a `find_command` that uses the `PATHEXE` env variable on
Windows to also search for other valid Git executables in addition to `.exe`.

http://environmentvariables.org/PathExt

This is the same approach Habitat took when they ran into this issue:

https://github.com/habitat-sh/habitat/pull/1290/files#diff-5fb0c7b1056276e7845dbf93cb430542R258
@Mark-Simulacrum
Copy link
Member

From the pull request: "It sounds like this behavior is specific to cmd.exe not CreateProcess. We're emulating the latter, so it sounds like we may not wish to merge this." As such, I'm going to close.

@cengiz-io
Copy link
Contributor

Hello @Mark-Simulacrum

Sorry for bumping this, I've a problem with .com files and this would fix that issue. Where shall I take that conversation?

@Mark-Simulacrum
Copy link
Member

Let's open a new issue, and please link here and to the PR. Are .com files found and executed by CreateProcess on Windows? If not, then I suspect the resolution will be similar, but if yes, then it seems like changing it is a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants