
今天的問答環節由SuperUser提供,這是Stack Exchange的一個細分,Stack Exchange是一個社區驅動的問答網站分組。
問題
超級用戶讀者傑克想要無形地運行BAT文件,他寫道:
I have installed a ruby gem called Redcar, which is launched from the command line. When it runs, it steals the shell until it terminates, so I have to create a new shell window to continue doing command line work. The shell I’m using is the GITBash shell from MySysGit.
I found a Redcar.bat file which is meant to launch Redcar as a shortcut, I presume, but I don’t want the extra command prompt window to open whenever I launch the BAT file.
How do I just run the BAT without seeing the prompt?
有沒有解決傑克隱身的快速慾望?
答案
超級用戶貢獻者Afrazier回應了壞消息和好消息:
You can’t - executing a batch file with the built in Command Prompt is going to keep a window open until the batch file exits.
What you can do is take steps to make sure that the batch file exits as quickly as possible. If at all possible, modify the batch file to run whatever program with the
start
命令。默認情況下,
start
立即返回而不等待程序退出,因此批處理文件將繼續運行,並且可能會立即退出。結合修改快捷方式以最小化運行批處理文件,您只會看到任務欄閃爍,甚至沒有看到屏幕上的窗口。
有一點需要注意的是,如果你正在運行一個控制台模式程序,許多腳本解釋器都是這樣,批處理文件將等待程序退出,並使用
start
將產生一個新的控制台窗口。在這種情況下,您需要做的是運行基於Windows的解釋器版本而不是基於控制台的版本 - 否
start
必要。對於Perl,你會跑
wperl.exe
代替
perl.exe
。對於Python,它是
pythonw.exe
代替
python.exe
。我下載的舊win32 Ruby發行版有
rubyw.exe
,應該做同樣的事情。
最後一種可能性是使用第三方工具運行帶有隱藏窗口的命令提示符。我聽說過這些東西,但從未對它們有用過,所以我不知道有什麼特別指向你的。
讀者還向他指出了另一個超級用戶線程,該線程強調瞭如何使用Visual Basic腳本來超越最小化可見性並直接隱藏CMD提示。在那個帖子中,Harry MC解釋說:
Solution 1:
Save this one line of text as file
invisible.vbs
:
CreateObject(“Wscript.Shell”)。運行“”“”&WScript.Arguments(0)&“”“”,0,False
要無形地運行任何程序或批處理文件,請像這樣使用它:
wscript.exe“C: Wherever invisible.vbs”“C: Some Other Place MyBatchFile.bat”
為了能夠傳遞/中繼參數列表,只使用兩個雙引號
CreateObject(“Wscript.Shell”)。運行“”&WScript.Arguments(0)&“”,0,False
例如:Invisible.vbs“Kill.vbs ME.exe”
解決方案2:
使用命令行工具靜默啟動進程:安靜。
根據您使用VBS和第三方工具的舒適程度採用上述任何解決方案,至少會降低CMD窗口的可見性或徹底刪除它。
有什麼要補充說明嗎?在評論中發聲。想要從其他精通技術的Stack Exchange用戶那裡閱讀更多答案嗎?在這裡查看完整的討論主題。