在Windows上运行控制台应用程序时禁止命令窗口

时间:2011-06-27 13:36:29

标签: windows vim command-line windows-xp

在Windows XP上运行控制台应用程序时,有没有办法抑制显示命令窗口?

详细信息:我正在调用来自Vim的(基于控制台的)程序。我希望每次执行此操作时都避免显示命令窗口。

7 个答案:

答案 0 :(得分:5)

尝试start /B <program name>在没有新窗口的情况下启动程序。

答案 1 :(得分:5)

您是否尝试过shell.vim

  

xolox#shell#execute()函数

     

此功能启用其他Vim   用于执行外部命令的插件   在后台(即   异步)没有打开   Windows上的命令提示符窗口。

答案 2 :(得分:3)

当我不想看到从Vim命令行调用的外部命令的输出时,我会用:silent作为前缀。但是,这会导致在MS Windows下运行GVim时,命令窗口会暂时闪烁在屏幕上。片刻之后,我对这种行为感到恼火,所以我研究了替代解决方案(这就是我遇到这个问题的方法)。

我提出的最佳解决方案是使用Vim的内置system function,它运行shell命令而无需打开外部命令窗口。虽然未打印shell命令的输出,但可通过v:shell_error方便地获取其退出状态。它还具有可跨(所有)平台移植的优势。

示例(如果echo存在,0语句应打印C:\Windows

call system("dir c:\windows")
echo v:shell_error

答案 3 :(得分:2)

我无法相信没有人建议只使用:沉默

例如,我的.vimrc(Win7上的gvim)

中有以下内容
"open windows explorer to the directory of the current file
:map <leader>ex :silent !Explorer %:p:h<CR> 

答案 4 :(得分:0)

你可以使用这种类型的autohotkey脚本:

Loop {
    WinWait, my command window title
    WinHide
}

答案 5 :(得分:0)

我试图在 Windows 上的 vim 中使用 git-bash 作为我的 shell,但是正如您所描述的那样,每当运行命令时都会打开命令提示符。我的最终解决方案是安装插件 xolox/vim-shell 并将以下代码段添加到 .vimrc

if has('win32')
        set shell=bash\ -c
        set shellcmdflag=
        set shellxquote='
        set shellquote=
        set shellredir=>
        set noshelltemp "This prevents an external window from opening.
endif

答案 6 :(得分:-1)

此实用程序也可以完成这项工作:

http://www.ntwind.com/software/utilities/hstart.html

相关问题