Cygwin - 从“运行命令”运行脚本静默

时间:2009-03-23 12:57:32

标签: command-line cygwin silent

我有脚本可以说:

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 command; exit不会自动终止该框 - 但是我可以手动终止它而不会终止IDE进程。 run命令接受快捷方式(.lnk's),bat's,exe's。

7 个答案:

答案 0 :(得分:38)

尝试cygwin的run.exe命令。这是一个大型安装,是Windows机器的完整unix环境。假设您在c:\cygwin\安装了它。

打开shell(bash)并输入man run

没有神秘感,只需运行c:\cygwin\bin\run.exe <your command here>即可执行无dos窗口。

您可以从任何DOS窗口运行它(从开始菜单运行cmd.exe)。你不需要从cygwin运行它。

为方便起见,请将C:\cygwin\bin附加到%PATH%env var(我的电脑→属性→高级→环境变量)(感谢Felipe Alvarez发表评论)。

现在你可以输入

run "C:\foo.bsh"

以下是runco​​mmand的手册页:

$ man run
RUN(1)                             run 1.3.0                            RUN(1)

NAME
       run - start programs with hidden console window

SYNOPSIS
       run [ -p path ] command [ -wait ] arguments

       runcommand [ -p path ] [ -wait ] arguments

DESCRIPTION
       Windows  programs  are  either  GUI  programs or console programs. When
       started console  programs  will  either  attach  to an existing console
       or  create a new one. GUI programs can  never attach to an exiting con‐
       sole. There is no way to attach to an existing console but hide  it  if
       started as GUI program.

       run  will  do this for you. It works  as intermediate and starts a pro‐
       gram but makes the console window hidden.

       With -p path you can add path to the PATH environment variable.

       Issuing -wait as first program  argument will make run wait for program
       completition, otherwise it returns immediately.

       The  second  variant  is  for   creating wrappers. If the executable is
       named runcommand (eg runemacs), run will try  to start the program  (eg
       emacs).

EXAMPLES
       run -p /usr/X11R6/bin xterm

       run emacs -wait
       runemacs -wait

       run make -wait

AUTHORS
       Charles S. Wilson

       Harold L Hunt II

       Jehan Bing

       Alexander Gottwald

Version 1.3.0                    November 2005                          RUN(1)

答案 1 :(得分:16)

你可以使用......

c:\cygwin\bin\bash -l /path/to/script_to_interpret.sh

...或...

c:\cygwin\bin\bash -l -c /path/to/executable_script.sh

注意: -l标志告诉bash“就像它已被登录直接调用一样”并使用Bash Startup Files。这很重要,因为它可以在启动cygwin终端时设置$ PATH和其他依赖的东西。如果您不包含-l--login,当您尝试拨打除内置bash之外的任何内容时,您将收到“未找到命令”。

2之间的区别就像做...之间的区别。

bash script_to_interpret.sh

...和...

./executable_script.sh

...在* nix中。前者使用bash解释脚本。后者执行脚本(仅当它具有chmod +x executable_script.sh)并根据其"shebang"行解释它。如果您的可执行文件根本不是脚本,那么后一种方法也是您想要做的,例如从源代码编译的* nix二进制文件。)

答案 2 :(得分:10)

一直困扰我一段时间我无法找到解决方案,但我终于得到了正确的组合。

如果你的PATH上有cygwin,你可以简单地执行以下操作:
run bash test.js

如果你的路上没有cygwin,你可以这样做:
c:\cygwin\bin\run.exe -p /bin bash test.js

如果您正在寻找对创建窗口的更多控制(最大化等),您似乎也可以使用cygstart

来源:
- neves在上面回答(虽然这对我个人而言本身并不足以弄明白) - http://cygwin.com/ml/cygwin/2008-09/msg00156.html

答案 3 :(得分:4)

由于终端无法在脚本仍在运行时关闭,请尝试以下命令:

"nohup C:\foo.bsh; exit" 

这样你的脚本将被背景化并与终端分离,它应该快速退出,以便终端消失。我认为用这种方法窗口可能仍然“闪烁”,但结果应该比你得到的更好。

答案 4 :(得分:3)

我正在运行Cygwin64,xwin服务器链接指向:

C:\ cygwin64 \ bin \ run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe

这会在任务栏上创建一个图标和一个通知。我不喜欢那样。该图标相当无用,通知中包含.XWinrc的所有菜单选项。

所以...我写了一个.vbs脚本来静默运行这个命令并使图标消失:

Set objShell = CreateObject("WScript.Shell")
objShell.Run("C:\cygwin64\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe"), 0

答案 5 :(得分:2)

另一个不完美的可能性是通过快捷方式运行脚本并将快捷方式的“运行”选项设置为“最小化”。

答案 6 :(得分:0)

转到已安装cygwin的目录(在我的机器上是c:/ cygwin64 / bin) 只需输入&#34; bash.exe&#34;

相关问题