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

Can't stack exec a .bat file #2225

Closed
ndmitchell opened this issue Jun 1, 2016 · 18 comments
Closed

Can't stack exec a .bat file #2225

ndmitchell opened this issue Jun 1, 2016 · 18 comments

Comments

@ndmitchell
Copy link
Contributor

Given a batch file hello.bat I can run it from the Windows command line with hello, hello.bat, cmd /c hello and cmd /c hello.bat. When running stack exec -- ... for any of those 4 variants, using stack-1.1.2 i386, I get one of:

C:\Neil\temp\stack-bat>stack exec -- cmd /c hello.bat
Run from outside a project, using implicit global project config
Using resolver: lts-2.14 from implicit global project's config file: C:\Users\ndmit_000\AppData\Roaming\stack\global\stack.yaml
C:\Users\ndmit_000\AppData\Local\Programs\stack\i386-windows\msys2-20150512\usr\bin\cmd: createProcess: invalid argument (Exec format error)
C:\Neil\temp\stack-bat>stack exec -- hello.bat
Run from outside a project, using implicit global project config
Using resolver: lts-2.14 from implicit global project's config file: C:\Users\ndmit_000\AppData\Roaming\stack\global\stack.yaml
Executable named hello.bat not found on path: ["C:\\Users\\ndmit_000\\AppData\\Roaming\\stack\\global\\.stack-work\\install\\1fc798c0\\bin","C:\\Users\\ndmit_000\\AppData\\Roaming\\stack\\snapshots\\0ac80986\\bin","C:\\Users\\ndmit_000\\App
... ]

The .bat suffix does not seem to make a difference.

@mboes
Copy link
Contributor

mboes commented Jun 5, 2016

I get the same error, using

$ stack exec -- pacman -Sy
$ stack exec -- pacman -S autoconf
$ stack exec -- autoreconf -i
C:\Users\appveyor\AppData\Local\Programs\stack\i386-windows\msys2-20150512\usr\bin\autoreconf: createProcess: invalid argument (Exec format error)

@mboes
Copy link
Contributor

mboes commented Jun 5, 2016

Note that autoreconf is a Perl script. I guess I could get around this by calling perl.exe and passing the full path to the autoreconf script to Perl, but that's pretty inconvenient. https://ghc.haskell.org/trac/ghc/ticket/365?cversion=0&cnum_hist=4#comment:7 suggests that rather than createProcess, stack exec should be using the ShellExecute() win32 call.

@mboes
Copy link
Contributor

mboes commented Jun 5, 2016

cc @snoyberg in case this is actually a process package issue.

@ndmitchell
Copy link
Contributor Author

Note that the path for getting a .bat file to work and a #! file to work should be entirely different. You should be able to get the autoreconf to work by doing sh autoreconf, since sh (but not Windows) can interpret #!.

However, the .bat issue is quite different since .bat is known to Windows. I don't think that bit is a process issue, as callCommand "hello.bat" and callProcess "hello.bat" [] both work fine. In fact, I'm slightly surprised it doesn't work with stack exec - they must be doing something a bit weird.

@ndmitchell
Copy link
Contributor Author

Btw, the argument that GHC should use ShellExecute is probably misguided. ShellExecute is not for running command line tools, its for opening files. Passing a .txt file as a preprocess should not spawn Notepad. Passing an email as a preprocessor should not open Outlook. It's entirely the wrong approach.

@mboes
Copy link
Contributor

mboes commented Jun 5, 2016

I see - I didn't realize that Windows has no concept of a shebang (I don't use the platform). For the .bat case, like you I'm not sure what's going on. But for the perl script case, sh -c autoreconf seems to work, and has the advantage over calling perl directly of at least being able to leverage the PATH to find the script location. Thanks!

@snoyberg
Copy link
Contributor

snoyberg commented Jun 6, 2016

There's some specific file-extension-searching logic present in Stack, which currently is hard-coded to just .exes. I'll push a PR momentarily to add .bat and .com as well. Requests:

  • Could someone test this on Windows? I don't have a Windows machine readily available right now
  • Any feedback on the list of extensions and recommend ordering of preference?

@snoyberg
Copy link
Contributor

snoyberg commented Jun 6, 2016

Opened PR #2247

@ndmitchell
Copy link
Contributor Author

There is actually an environment variable on Windows that both gives you the complete list of extensions and the correct ordering.

C:\Neil>echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

@ndmitchell
Copy link
Contributor Author

After the patch in #2247 I can run stack exec .\hello.bat but not stack exec hello.bat. My guess is on Windows you aren't checking the cwd which should implicitly be on the PATH, for consistency with the rest of Windows.

@snoyberg
Copy link
Contributor

snoyberg commented Jun 6, 2016

I've pushed a commit hopefully addressing both points, can you give it a
shot?

On Mon, Jun 6, 2016 at 11:20 AM, Neil Mitchell notifications@github.com
wrote:

There is actually an environment variable on Windows that both gives you
the complete list of extensions and the correct ordering.

C:\Neil>echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
#2225 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AADBB_ZGpq6nN2zTCFzp9I-7t7vixGLKks5qI9g9gaJpZM4IrwT-
.

@ndmitchell
Copy link
Contributor Author

Seemingly had no effect:

C:\Neil\temp>stack exec hello.bat
Run from outside a project, using implicit global project config
Using resolver: lts-6.1 from implicit global project's config file: C:\Users\ndmit_000\AppData\Roaming\stack\global\stack.yaml
Populated index cache.
Did not find .cabal file for stack-1.1.2 with Git SHA of 78d31fa4367593f8408ac142d2c3b40da54c247b
Did not find .cabal file for postgresql-simple-0.5.2.0 with Git SHA of e9dc0cb5cd5d7fb3d0023bfacba48ddcc5b4712f
Did not find .cabal file for pcre-utils-0.1.8 with Git SHA of c3c1b258c4b15aeb49b84ffe7cc3e0a77727a42d
Did not find .cabal file for opaleye-0.4.2.0 with Git SHA of bd719541cfb6d6eefe00172d228bb3331c73704b
Did not find .cabal file for irc-dcc-1.2.1 with Git SHA of 34ed39699e28cadbdcec2601622b39198dbffabc
Did not find .cabal file for compactmap-0.1.4 with Git SHA of fb9637ad073f5a328cd82361ee9296d45f3a9bbe
Executable named hello.bat not found on path: ["C:\\Users\\ndmit_000\\AppData\\Roaming\\stack\\global\\.stack-work\\install\\9317f0e6\\bin",...]

C:\Neil\temp>stack exec .\hello.bat
Run from outside a project, using implicit global project config
Using resolver: lts-6.1 from implicit global project's config file: C:\Users\ndmit_000\AppData\Roaming\stack\global\stack.yaml

C:\Neil\temp>echo klj12
klj12

C:\Neil\temp>stack exec .\hello
Run from outside a project, using implicit global project config
Using resolver: lts-6.1 from implicit global project's config file: C:\Users\ndmit_000\AppData\Roaming\stack\global\stack.yaml
Did not find executable at specified path: .\hello

C:\Neil\temp>stack --version
Version 1.1.3, Git revision a28aea9bc8e10782fd09c9fca04802a2f93ed797 i386 hpack-0.14.0

@snoyberg
Copy link
Contributor

snoyberg commented Jun 6, 2016

stack --version
Version 1.1.3, Git revision a28aea9bc8e10782fd09c9fca04802a2f93ed797 i386 hpack-0.14.0

This is all going on in a separate branch, namely:

commit d5b8a7720ae8e0a3a6790e7de35863c9cbd43f59
branch 2225-executable-extension-windows

@ndmitchell
Copy link
Contributor Author

Sorry @snoyberg - got confused by github. Upgraded to something actually including your code and it worked perfectly - much appreciated.

@snoyberg
Copy link
Contributor

snoyberg commented Jun 6, 2016

Awesome, thanks for checking. I'll add a comment to the PR.

@ndmitchell
Copy link
Contributor Author

Only potential remark is that you fall back to ["", ".exe", ".bat", ".com"] while PATHEXT defaults to .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC. I'd be tempted to match the order, include CMD, and also go upper case. I appreciate upper case shouldn't be relevant, but if it is, I imagine the normal and fallback cases doing different things will cause something to go wrong.

@snoyberg
Copy link
Contributor

snoyberg commented Jun 6, 2016

Good point, I even thought to myself that I should make that change and
then forgot. Updated.

On Mon, Jun 6, 2016 at 2:48 PM, Neil Mitchell notifications@github.com
wrote:

Only potential remark is that you fall back to ["", ".exe", ".bat",
".com"] while PATHEXT defaults to
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC. I'd be tempted to
match the order, include CMD, and also go upper case. I appreciate upper
case shouldn't be relevant, but if it is, I imagine the normal and fallback
cases doing different things will cause something to go wrong.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2225 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AADBByasHLC3k6BhHCE3HAoz8VNEqdXUks5qJAkIgaJpZM4IrwT-
.

mgsloan added a commit that referenced this issue Jun 6, 2016
…sion-windows

Support most executable extensions on Windows #2225
@mgsloan
Copy link
Contributor

mgsloan commented Jun 6, 2016

Resolved via @snoyberg 's PR

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

No branches or pull requests

5 participants