Cygwin - 从"运行命令"运行脚本静默

Rus*_*uss 36 command-line cygwin silent

我有脚本让我们说:

C:\foo.bsh
Run Code Online (Sandbox Code Playgroud)

我希望能够通过windows run命令运行此命令:

Start -> Run
Windows Key + R
Run Code Online (Sandbox Code Playgroud)

并输入类似'foo'的小东西并点击返回.

但是,我不希望cmd提示可见.此脚本为IDE执行一些预处理.我不希望cmd提示符在IDE进程的生命周期内打开.

我试过了:

1)使用以下内容创建bat文件:

c:\cygwin\bin\bash --login "C:\foo.bsh" (this fails because it keeps a cmd open)
Run Code Online (Sandbox Code Playgroud)

2)使用bat_2_exe_converter将上面的bat文件转换为exe(不使cmd静音)

想法?

编辑:到目前为止,解决方案建议从实际的cygwin shell中输入内容.我试图通过缩短我可以在Windows运行命令中输入的内容来获得更快的解决方案.此外,nohup command; exit它不会自动杀死盒子 - 但是我可以手动杀死它而不会杀死IDE进程.run命令接受快捷方式(.lnk's),bat's,exe's.

nev*_*ves 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(我的电脑→属性→高级→环境变量)(Kudos to Felipe Alvarez评论).

现在你可以输入

run "C:\foo.bsh"
Run Code Online (Sandbox Code Playgroud)

这是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)
Run Code Online (Sandbox Code Playgroud)

  • 有没有办法得到输出? (2认同)
  • @Lime 要获取输出,请使用 ```bash``` 命令: ```C:\\cygwin64\\bin\\bash --login -c 'foo.bsh``` (2认同)

Fel*_*rez 17

你可以使用......

c:\cygwin\bin\bash -l /path/to/script_to_interpret.sh
Run Code Online (Sandbox Code Playgroud)

...要么...

c:\cygwin\bin\bash -l -c /path/to/executable_script.sh
Run Code Online (Sandbox Code Playgroud)

注意:-l标志告诉bash"就像它已被登录直接调用一样"并使用Bash Startup Files.这很重要,因为它可以在启动cygwin终端时设置$ PATH和其他依赖的东西.如果你没有包含,-l或者--login当你试图调用除了bash内置之外的任何东西时你会得到"命令未找到".

2之间的差异就像做...之间的区别

bash script_to_interpret.sh
Run Code Online (Sandbox Code Playgroud)

...和...

./executable_script.sh
Run Code Online (Sandbox Code Playgroud)

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


stu*_*eek 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


Dan*_*ane 4

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

"nohup C:\foo.bsh; exit" 
Run Code Online (Sandbox Code Playgroud)

这样,您的脚本将在后台运行并与终端分离,并且它应该快速退出,以便终端消失。我认为这种方法的窗口可能仍然会“闪烁”,但结果应该比您得到的更好。