windows Cygwin 自动脚本启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5098010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cygwin automatic script launch
提问by Bombillazo
Im trying to automatically run a script using Cygwin via CMD. I basically created a BAT file that goes to the directory and executes an .SH file. SH files are accosiated with Cygwin, and I tried something like "cygwin update.sh" in the command line. But all it really does is open Cygwin. I want Cygwin to automatically run the script file. Is there any easy way to do this, I've been trying to find but can't. Thank you!
我试图通过 CMD 使用 Cygwin 自动运行脚本。我基本上创建了一个 BAT 文件,该文件转到该目录并执行一个 .SH 文件。SH 文件与 Cygwin 相关联,我在命令行中尝试了类似“cygwin update.sh”的内容。但它真正做的只是打开 Cygwin。我希望 Cygwin 自动运行脚本文件。有没有什么简单的方法可以做到这一点,我一直试图找到但不能。谢谢!
采纳答案by 0xC0000022L
You'll want to call the shell script with a particular shell, e.g. bash.
您需要使用特定的 shell(例如 bash)调用 shell 脚本。
When having Cygwin open, call which bash
to figure out where the binary is located. Cygwin also comes with tools that can convert paths between Cygwin and Win32 form, which is pretty helpful in cases like yours.
打开 Cygwin 后,调用which bash
以确定二进制文件的位置。Cygwin 还附带了可以在 Cygwin 和 Win32 形式之间转换路径的工具,这对于像您这样的情况非常有用。
There is one other thing that may work, depending on your setup. There is an environment variable named PATHEXT
which declares file extensions that are deemed "executable" by CMD. This can be used to your advantage, if Windows is configured so that the shell's "open" verb executes the correct shell for the file extension .sh
(in your case).
根据您的设置,还有一件事可能有效。有一个名为的环境变量PATHEXT
,用于声明 CMD 认为“可执行”的文件扩展名。如果 Windows 配置为使外壳程序的“打开”动词为文件扩展名.sh
(在您的情况下)执行正确的外壳程序,则这可以对您有利。
Good luck.
祝你好运。
回答by Bombillazo
I also found this!
我也发现了这个!
I didn't quite understand it at first, but then it worked as I wanted it. Just if anyone knows, is there a way to make the script run without the CMD window open?? Thanks
一开始我不太明白,但后来它如我所愿。如果有人知道,有没有办法让脚本在不打开 CMD 窗口的情况下运行?谢谢
回答by dave_k_smith
From Cygwin Terminal, read man mintty
. Try something like the following from a Windows Command Prompt:
从 Cygwin 终端,阅读man mintty
. 从 Windows 命令提示符尝试类似以下内容:
c:\cygwin\bin\mintty --hold always --exec /cygdrive/c/path/to/bash/script.sh