winpty icon indicating copy to clipboard operation
winpty copied to clipboard

Winpty on iex (Elixir)

Open CMCDragonkai opened this issue 7 years ago • 3 comments

In the past I reported this issue with Elixir: https://github.com/elixir-lang/elixir/issues/2597

Just today I started trying to use winpty with iex installed from Chocolatey.

Winpty doesn't work with iex.bat nor iex.

Reporting errors like:

winpty 'fullpath to iex'
Could not start 'C...': %1 is not a valid Win32 application. (error 0xc1)

Also with iex.bat, it says something about '#!' is not recognized.

CMCDragonkai avatar Feb 07 '18 04:02 CMCDragonkai

What does winpty --version report?

winpty iex doesn't work for me, but winpty iex.bat does.

$ which iex
/cygdrive/c/ProgramData/chocolatey/lib/Elixir/bin/iex
$ which iex.bat
/cygdrive/c/ProgramData/chocolatey/lib/Elixir/bin/iex.bat
$ iex --version
IEx 1.6.0 (compiled with OTP 19)

$ winpty --version
winpty version 0.4.4-dev
commit 850661d02bd8b9e5b7c802da51cf47d1140f49dd

$ winpty iex
winpty: error: cannot start 'iex': Not found in PATH
$ winpty iex.bat
Interactive Elixir (1.6.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Terminate batch job (Y/N)? Y

$ winpty $(which iex)
winpty: error: cannot start 'C:\ProgramData\chocolatey\lib\Elixir\bin\iex': %1 is not a valid Win32 application. (error 0xc1)
$ winpty $(which iex).bat
Interactive Elixir (1.6.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Terminate batch job (Y/N)? Y

Apparently when winpty's findProgram function is searching the PATH, it doesn't try combinations of extensions. I think it needs to try com, bat, and cmd (if not exe). There are a bunch of extensions I see in %PATHEXT% like js and py that won't work with the CreateProcess API that winpty uses.

When winpty searches the PATH, it requires that it can call Cygwin's access on a candidate path. It doesn't have to add the exe extension explicitly because Cygwin reports that foo exists if foo.exe is the actual Win32 name. This magic doesn't apply to names ending in other extensions like .bat or .com.

I suppose winpty $(which iex) should also work, because $(which iex).bat exists?

I see that Cygwin where foo won't find a foo.bat in the PATH, but Win32 where.exe foo will find it.

rprichard avatar Feb 07 '18 08:02 rprichard

winpty version 0.4.0
commit c66253e78217d8188a5e3f6048c6709bd2dfc59b

Maybe I shall upgrade and try again.

CMCDragonkai avatar Feb 07 '18 11:02 CMCDragonkai

I tried the batch scripts now. Now they work properly.

Is there a way to make winpty lookup the .bat versions as well?

CMCDragonkai avatar Feb 07 '18 12:02 CMCDragonkai