Cygwin - 从“运行命令”静默运行脚本
我有脚本可以说:
C:\foo.bsh
我希望能够通过 windows run 命令运行此命令:
Start -> Run
Windows Key + R
并输入一些小内容,例如“foo”并按回车键。
但是,我不希望 cmd 提示符可见。 该脚本为 IDE 进行一些预处理。 我不希望 cmd 提示符在 IDE 进程的生命周期内保持打开状态。
我尝试过:
1)创建一个包含以下内容的bat文件:
c:\cygwin\bin\bash --login "C:\foo.bsh" (this fails because it keeps a cmd open)
2)使用bat_2_exe_converter将上述bat文件转换为exe(不会使cmd静音)
有什么想法?
编辑: 到目前为止,解决方案建议从实际的 cygwin shell 中输入一些内容。 我试图通过输入简短的 Windows 运行命令来获得更快的解决方案。 另外,nohup 命令; exit 不会自动终止该框 - 但是我可以手动终止它而不终止 IDE 进程。 运行命令接受快捷方式(.lnk)、bat、exe。
I have script lets say:
C:\foo.bsh
I want to be able to run this command via the windows run command:
Start -> Run
Windows Key + R
and type something small like 'foo' and hitting return.
However, I do not want a cmd prompt to be visible. This script does some preprocessing for an IDE. I do not want the cmd prompt to be open for the lifetime of the IDE process.
I have tried:
1) Creating a bat file with the following contents:
c:\cygwin\bin\bash --login "C:\foo.bsh" (this fails because it keeps a cmd open)
2) Converting the above bat file to an exe using bat_2_exe_converter (does not make the cmd silent)
thoughts?
EDIT: The solution so far suggests something to type from an actual cygwin shell. I am trying to get a faster solution by having something short I can type in the Windows run command. Also, the nohup command; exit
doesn't automatically kill the box - however I can manually kill it without killing the IDE process. The run command accepts shortcuts (.lnk's), bat's, exe's.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
尝试 cygwin 的 run.exe 命令。 这是一个大型安装,为您的 Windows 机器提供了一个完整的 UNIX 环境。 假设您将其安装在
c:\cygwin\
中。没什么神秘的,只需运行
c:\cygwin\bin\run.exe
即可获得无 dos 窗口执行。您可以从任何 DOS 窗口运行它(从开始菜单运行 cmd.exe)。 您不需要从 cygwin 运行它。
为了使其更容易,请将
C:\cygwin\bin
附加到您的 %PATH% env var(我的电脑 → 属性 → 高级 → 环境变量)(感谢 Felipe Alvarez 评论)。现在,您只需键入“
您必须使用此命令在开始菜单中创建一个链接”,以便能够使用 Win-R 运行它。
这是 run 命令的手册页:
Try the run.exe command of cygwin. It is a big install, a complete unix environment for your Windows machine. Suppose you installed it at
c:\cygwin\
.No mystery, just run
c:\cygwin\bin\run.exe <your command here>
and you will have your no dos window execution.You can run it from any DOS window (run cmd.exe from the start menu). You don't need to run it from cygwin.
To make it easier, append
C:\cygwin\bin
to your %PATH% env var (My Computer → Properties → Advanced → Environment Variables) (Kudos to Felipe Alvarez comment).Now you can just type
You must create a link in your Start Menu with this command so will be able to run it with Win-R.
Here is the man page of the runcommand:
您可以使用...
...或...
注意:
-l
标志告诉 bash “就像通过登录直接调用一样”并且使用 Bash 启动文件。 这很重要,因为它设置您的 $PATH 以及启动 cygwin 终端时所依赖的其他内容。 如果您不包含-l
或--login
,当您尝试调用除 bash 内置函数之外的任何内容时,您将收到“command not found”。两者之间的区别就像
执行...和
在*nix 中 ... 之间的区别。 前者使用 bash 解释脚本。 后者执行脚本(仅当它具有
chmod +xexecutable_script.sh
时)并根据其 “shebang”行。 如果您的可执行文件根本不是脚本,例如从源代码编译的 *nix 二进制文件,则后一种方法也是您想要执行的方法。)You can use either...
...or...
Note: the
-l
flag tell bash to "act as if it had been directly invoked by login" and use Bash Startup Files. This is important in that it sets your $PATH and other things you rely on when you launch a cygwin terminal. If you don't include-l
or--login
you will get "command not found" when you try to call anything except of a bash builtin.The difference between the 2 is like the difference between doing...
...and...
...in *nix. The former interprets the script using bash. The latter executes the script (only if it has
chmod +x executable_script.sh
) and interprets it according to its "shebang" line. The latter method is also what you want to do if your executable is not a script at all, like a *nix binary compiled from source.)它已经困扰我一段时间了,我找不到解决方案,但我终于找到了正确的组合。
如果您的 PATH 中有 cygwin,您可以简单地执行以下操作:
运行 bash test.js
如果 cygwin 不在您的路径上,您可以执行以下操作:
c:\cygwin\bin\run.exe -p /bin bash test.js
如果您正在寻找对创建的窗口的更多控制(最大化等),看起来您可以使用
cygstart 也。
来源:
- 内维斯在上面回答(尽管这本身不足以让我个人弄清楚)
- http://cygwin.com/ml/cygwin/2008-09/msg00156.html
It has been bugging me for a while I couldn't find the solution for this, but I finally got the right mix together.
You can simply do the following if you have cygwin on your PATH:
run bash test.js
If cygwin is not on your path, you can do this:
c:\cygwin\bin\run.exe -p /bin bash test.js
If you are looking for more control over the created window (maximize, etc) it looks like you can use
cygstart
also.Sources:
- neves answer above (though that wasn't enough by itself for me personally to figure it out)
- http://cygwin.com/ml/cygwin/2008-09/msg00156.html
由于脚本仍在运行时终端无法关闭,请尝试以下命令:
这样您的脚本将在后台运行并与终端分离,并且它应该快速退出,以便终端消失。 我认为这种方法的窗口可能仍然会“闪烁”,但结果应该比您得到的更好。
As the terminal can't close while your script is still running, try the command:
This way your script will be backgrounded and detached from the terminal, and it should exit quickly so the terminal goes away. I think that the window may still 'flash' with this approach, but the results should be better than what you're getting.
我正在运行 Cygwin64 并且 xwin 服务器链接指向:
C:\cygwin64\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe
这将创建一个图标和一个通知在任务栏上。 我不喜欢那样。 该图标毫无用处,通知包含 .XWinrc 中的所有菜单选项。
所以...我编写了一个 .vbs 脚本来静默运行此命令并使图标消失:
I'm running Cygwin64 and the xwin server link points to:
C:\cygwin64\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe
This creates an icon AND a notification on the taskbar. I don't like that. The icon is rather useless, the notification has all your menu options from .XWinrc.
So... I wrote a .vbs script to silently run this command and make the icon go away:
另一种不完美的可能性是通过快捷方式运行脚本并将快捷方式的运行选项设置为“最小化”。
Another imperfect possibility is to run the script via a shortcut and set the shortcut's Run option to "minimized".
进入你安装cygwin的目录(在我的机器上是c:/cygwin64/bin)
一旦出现,只需输入“bash.exe”
Go to the directory where you have installed cygwin(on my machine it is c:/cygwin64/bin)
Once there simply type "bash.exe"