Skip to content

Make sure Which() on Windows platform always return the command with …#239

Merged
ariporad merged 1 commit intoshelljs:masterfrom
microsoft:users/tihuang/fixwhich
Jan 13, 2016
Merged

Make sure Which() on Windows platform always return the command with …#239
ariporad merged 1 commit intoshelljs:masterfrom
microsoft:users/tihuang/fixwhich

Conversation

@TingluoHuang
Copy link
Copy Markdown
Contributor

…extension.

@TingluoHuang
Copy link
Copy Markdown
Contributor Author

For issue #238.

@mtscout6
Copy link
Copy Markdown

mtscout6 commented Oct 9, 2015

This looks reasonable to me @arturadib thoughts?

@arturadib
Copy link
Copy Markdown
Collaborator

👍

@nfischer
Copy link
Copy Markdown
Member

nfischer commented Jan 8, 2016

It looks like the priority of .bat, .cmd, and .exe is not correct here.

I tested this on my Windows 7 64-bit machine as follows: I created files in my path named test.bat, test.cmd, and test.exe. Each file performs a simple print statement to help distinguish it from the other files. Here is what I saw:

> test # calls test.exe, not the others
this is exe
> del test.exe
> test # since there's no .exe, it calls .bat
this is bat
> del  test.bat
> test # since there's no .exe or .bat, it calls .cmd
this is cmd

So I think that which() should check for extensions in the order:

  1. .exe
  2. .bat
  3. .cmd

@TingluoHuang would you be able to add this to your PR? Aside from that, this looks ready to merge.

@TingluoHuang
Copy link
Copy Markdown
Contributor Author

@nfischer
attempt = baseAttempt + '.exe';
attempt = baseAttempt + '.cmd';
attempt = baseAttempt + '.bat';
The current priority in the code is already this one you want, isn't it?

@nfischer
Copy link
Copy Markdown
Member

nfischer commented Jan 8, 2016

I believe that the current (incorrect) priority is .exe, .cmd, .bat (ecb), and I believe the correct priority is .exe, .bat, .cmd (ebc, not ecb). Let me know if I'm missing something.

@nfischer
Copy link
Copy Markdown
Member

@TingluoHuang can you verify that the priority is as I described? If so, and we get that fixed in the code, then I think this is good to merge.

@nfischer nfischer self-assigned this Jan 12, 2016
@nfischer nfischer added fix Bug/defect, or a fix for such a problem medium priority labels Jan 12, 2016
@TingluoHuang
Copy link
Copy Markdown
Contributor Author

@nfischer The priority you mentioned is correct, i update the PR.

@nfischer
Copy link
Copy Markdown
Member

@TingluoHuang Can you rebase off master and squash your commits? I think this is safe to merge after that (if it passes the CI).

Once we get Windows CI running, we should probably add a specific test case for this, but we can do that later.

@TingluoHuang TingluoHuang force-pushed the users/tihuang/fixwhich branch from 11a731c to 9ca9b61 Compare January 13, 2016 20:04
@nfischer
Copy link
Copy Markdown
Member

LGTM. @arturadib @ariporad Feel free to merge

ariporad added a commit that referenced this pull request Jan 13, 2016
Make sure Which() on Windows platform always return the command with …
@ariporad ariporad merged commit e616aa6 into shelljs:master Jan 13, 2016
@ariporad
Copy link
Copy Markdown
Contributor

👍

@BYK
Copy link
Copy Markdown
Contributor

BYK commented Jan 14, 2016

Windows has a PATHEXT environment variable that tells which files are "self executable". Instead of a fixed list of .exe, .cmd etc we should probably use that. Similar code in Python: https://github.com/scopatz/xonsh/blob/57e7c1f43879e6394342a17638f2a9b6cb80bc23/xonsh/built_ins.py#L284-L298

@BYK
Copy link
Copy Markdown
Contributor

BYK commented Jan 14, 2016

FYI I'm willing to submit a PR that does this if you agree :)

@nfischer
Copy link
Copy Markdown
Member

@BYK would #134 be along the lines of what you're talking about? Perhaps we should ping that thread and see if that could get rebased off master.

I wasn't aware of the variable, but it seems like it's the right way to go. Thanks for bringing it to my attention!

@BYK
Copy link
Copy Markdown
Contributor

BYK commented Jan 15, 2016

@nfischer no problem :) Also reviewed the new patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug/defect, or a fix for such a problem medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants