Cygwin Bash from Windows Cmd Not Running Executable

情到浓时终转凉″ 提交于 2019-12-04 01:58:21

问题


I have a program I've compiled in cygwin, that I am trying to call from a batch file a la:

D:\cygwin\bin\bash --login -i C:/ILS/trunk/NAVAID/test.exe

But I am getting the error:

bash: C:/ILS/trunk/NAVAID/test.exe: cannot execute binary file

When I file test.exe inside cygwin, I get:

test.exe: PE32 executable (console) Intel 80386, for MS Windows

Any ideas why it won't run? Most of the errors I've found online are from people trying to run Linux apps, but this is something compiled (via g++) directly in cygwin (on the same machine).

On Windows 8 if it matters.


回答1:


You may try -c <command >

D:\cygwin\bin\bash --login -c C:/ILS/trunk/NAVAID/test.exe

This runs test.exe under a bash shell. Details on -c option

There are several single-character options that may be supplied at invocation which are not available with the set builtin.

-c string Read and execute commands from string after processing the options, then exit. Any remaining arguments are assigned to the positional parameters, starting with $0.

-i starts an interactive shell, that is not something you want in this case.

Finally for the sake of completion - bash has --rcfile <file path> option to give a startup file.




回答2:


This issue is you are dealing with 2 different interpreters, cmd.exe and Bash.

  • cmd.exe is designed to be used with Native Windows programs and Batch files
  • Cygwin Bash is designed to be used with Cygwin programs and Bash scripts.

You are trying to use a Cygwin program with a Batch file, which by now you can see is A Bad Thing. If you insist on using a Batch file you should

  • recompile the Cygwin program as a Native Windows program using i686-w64-mingw32-gcc

or

  • add Cygwin to the PATH as C:\cygwin\bin

then you can add the program to the Batch file like this

C:\ILS\trunk\NAVAID\test.exe


来源:https://stackoverflow.com/questions/15721597/cygwin-bash-from-windows-cmd-not-running-executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!