简体   繁体   English

来自Windows Cmd的Cygwin Bash未运行可执行文件

[英]Cygwin Bash from Windows Cmd Not Running Executable

I have a program I've compiled in cygwin, that I am trying to call from a batch file a la: 我有一个我在cygwin编译的程序,我试图从批处理文件中调用一个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: 当我在cygwin中提交test.exe时,我得到:

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). 我在网上找到的大多数错误来自试图运行Linux应用程序的人,但这是在cygwin(在同一台机器上)直接编译(通过g ++)。

On Windows 8 if it matters. 在Windows 8上,如果重要的话。

You may try -c <command > 你可以试试-c <command >

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

This runs test.exe under a bash shell. 这在bash shell下运行test.exe。 Details on -c option 有关-c选项的详细信息

There are several single-character options that may be supplied at invocation which are not available with the set builtin. 调用时可能会提供几个单字符选项,这些选项在set builtin中不可用。

-c string Read and execute commands from string after processing the options, then exit. -c string处理选项后从字符串读取并执行命令,然后退出。 Any remaining arguments are assigned to the positional parameters, starting with $0. 任何剩余的参数都分配给位置参数,从$ 0开始。

-i starts an interactive shell , that is not something you want in this case. -i启动一个交互式shell ,在这种情况下,这不是你想要的东西。

Finally for the sake of completion - bash has --rcfile <file path> option to give a startup file. 最后为了完成 - bash有--rcfile <file path>选项来提供启动文件。

This issue is you are dealing with 2 different interpreters, cmd.exe and Bash. 这个问题是你正在处理2个不同的解释器,cmd.exe和Bash。

  • cmd.exe is designed to be used with Native Windows programs and Batch files cmd.exe旨在与本机Windows程序和批处理文件一起使用
  • Cygwin Bash is designed to be used with Cygwin programs and Bash scripts. Cygwin Bash旨在与Cygwin程序和Bash脚本一起使用。

You are trying to use a Cygwin program with a Batch file, which by now you can see is A Bad Thing. 您正在尝试将Cygwin程序与批处理文件一起使用,现在您可以看到它是一件糟糕的事情。 If you insist on using a Batch file you should 如果你坚持使用批处理文件,你应该

  • recompile the Cygwin program as a Native Windows program using i686-w64-mingw32-gcc 使用i686-w64-mingw32-gcc将Cygwin程序重新编译为Native Windows程序

or 要么

  • add Cygwin to the PATH as C:\\cygwin\\bin 将Cygwin作为C:\\cygwin\\bin添加到PATH

then you can add the program to the Batch file like this 然后你可以像这样将程序添加到批处理文件中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM