开发者

Suppress command window when running console application on Windows

Is there a way to suppress showing the command window when running a console application on Windows XP?

Details: I am calling a (console-based) program fr开发者_运维技巧om Vim. I would like to avoid the command window being shown every time I do this.


Try start /B <program name> to start the program without a new window.


Did you try shell.vim?

The xolox#shell#execute() function

This function enables other Vim plug-ins to execute external commands in the background (i.e. asynchronously) without opening a command prompt window on Windows.


i can't believe no one has suggested simply using :silent

for example, I have the following in my .vimrc (gvim on Win7)

"open windows explorer to the directory of the current file
:map <leader>ex :silent !Explorer %:p:h<CR> 


When I didn’t want to see the output of external commands called from the Vim command line, I would prepend them with :silent. However, this results in a command window momentarily flashing on screen when running GVim under MS Windows. After a short while, I got annoyed by this behaviour so I researched alternative solutions (which is how I came across this question).


The best solution I came up with was to use Vim’s inbuilt system function which runs shell commands without opening an external command window. While the output of the shell command is not printed, its exit status is conveniently available via v:shell_error. It also has the advantage that it’s portable across (all) platforms.

Example (the echo statement should print 0 if C:\Windows exists):

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


You could maybe use some autohotkey script of this kind:

Loop {
    WinWait, my command window title
    WinHide
}


I was trying to use git-bash as my shell from vim on Windows but having the command prompt open whenever a command was run, as you described. My eventual solution was to install the plugin xolox/vim-shell and add the following snippet to .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


This utility will also do the job:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜