Why is it that Cygwin can run .bat scripts?

北慕城南 提交于 2019-12-29 06:37:09

问题


When I execute a .bat script from bash in Cygwin, by what mechanism is it running? I understand that if I run a .EXE it will launch, regardless of whether the .EXE is from Cygwin or from a more traditional environment. I understand that when I execute an executable script with #! at the beginning that Cygwin supplies the magic for it to run.

But why does a .bat script work? Is there some component inside of Cygwin that is aware of what a Windows .bat script is and what to do with it? Or is it that it is somehow impossible under Windows to execute a call to launch a .EXE file that won't automatically also work for a .bat script instead?


回答1:


Running

./test.bat params

from bash seems to be equivalent to

cmd /c test.bat params



回答2:


I believe that bash in cygwin sees the bat extension as being flagged executable (a cygwin hit-tip to windows convention). As such it loads and executes the file with it's associated interpreter (cmd.exe, per os configuration), much as it creates a new instance of bash to run your #! scripts (per posix standard).




回答3:


And if you want to fork an *.cmd file execution like a ShellScript process and append his log to an file:

cmd /c test.bat > nohup.out &

Enjoy!



来源:https://stackoverflow.com/questions/787522/why-is-it-that-cygwin-can-run-bat-scripts

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