我可以在沒有可見命令提示符的情況下執行windows批處理檔案嗎?

今天的問答環節是由SuperUser提供的,SuperUser是Stack Exchange的一個分支,是一個由社群驅動的問答網站分組。...

我可以在沒有可見命令提示符的情況下執行windows批處理檔案嗎?Batch files are a handy way to execute a series of commands in Windows, but is there anyway to run them invisibly in the background? Read on find out how.

今天的問答環節是由SuperUser提供的,SuperUser是Stack Exchange的一個分支,是一個由社群驅動的問答網站分組。

問題

超級使用者讀者Jake想隱形執行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 command. By default, start returns immediately without waiting for the program to exit, so the batch file will continue to run and, presumably, exit immediately. Couple that with modifying your shortcut to run the batch file minimized, and you’ll only see the taskbar flash without even seeing a window ***creen.

One caveat to this is that if you’re running a c***ole-mode program, which many script interpreters are, the batch file will wait for the program to exit, and using start will spawn a new c***ole window. What you need to do in this case is run the Windows-based version of the interpreter instead of the c***ole-based one — no start necessary. For Perl, you would run wperl.exe instead of perl.exe. For Python, it’s pythonw.exe instead of python.exe. The old win32 Ruby distribution I have downloaded has rubyw.exe, which should do the same thing.

A final possibility is to use a 3rd-party tool to run the command prompt with a hidden window. I’ve heard of such things but never had a use for them, so I don’t know of anything in particular to point you to.

讀者還向他指出了另一個超級使用者執行緒,該執行緒強調了如何使用visualbasic指令碼來超越最小化可見性和完全隱藏CMD提示符的限制。在這篇文章中,Harry MC解釋道:

Solution 1:

Save this one line of text as file invisible.vbs:

CreateObject(“Wscript.Shell”).Run “””” & WScript.Arguments(0) & “”””, 0, False

To run any program or batch file invisibly, use it like this:

wscript.exe “C:\Wherever\invisible.vbs” “C:\Some Other Place\MyBatchFile.bat”

To also be able to pass-on/relay a list of arguments use only two double quotes

CreateObject(“Wscript.Shell”).Run “” & WScript.Arguments(0) & “”, 0, False

eg: Invisible.vbs “Kill.vbs ME.exe”

Solution 2:

Use a command line tool to silently launch a process : Quiet.

根據您是否使用VBS和第三方工具的舒適程度,使用上述任何解決方案,都將至少降低CMD視窗的可見性或完全刪除它。


有什麼要補充的解釋嗎?在評論中發出聲音。想從其他精通技術的Stack Exchange使用者那裡瞭解更多答案嗎?在這裡檢視完整的討論主題。

 

  • 發表於 2021-04-12 03:23
  • 閱讀 ( 48 )
  • 分類:網際網路

你可能感興趣的文章

如何透過五個簡單步驟建立批處理(bat)檔案

... 假設您經常遇到網路問題;您經常在命令提示符下輸入ipconfig並ping Google來解決網路問題。過了一段時間,你意識到如果你只寫一個簡單的BAT檔案,把它放在隨身碟上,然後把它用在你的機器上,效率會更高一些...

  • 發佈於 2021-03-23 08:09
  • 閲讀 ( 46 )

如何有效地建立和管理python虛擬環境

... 要在Windows上建立虛擬環境,請在所選位置開啟命令提示符視窗。鍵入mkdir[Folder]建立一個新資料夾,用所選名稱替換文字和方括號。 ...

  • 發佈於 2021-03-30 13:53
  • 閲讀 ( 82 )

如何在linux上使用at和batch來排程命令

...新增一分鐘,如下所示: at now + 1 minute at打印出訊息和at提示符,並等待您鍵入要排程的命令。不過,首先要考慮以下資訊: 它告訴您至少啟動一個sh shell例項,並在其中執行命令。您的命令不會在bashshell中執行,bashshell與shshe...

  • 發佈於 2021-04-02 18:33
  • 閲讀 ( 67 )

linux上的stdin、stdout和stderr是什麼?

...案,所以終端視窗中沒有可見的輸出。我們返回到命令列提示符,好像什麼都沒有發生。 讓我們檢查每個檔案的內容: cat capture.txt cat error.txt 將stdout和stderr重定向到同一個檔案 這很好,我們將每個標準輸出流都放到了自己的...

  • 發佈於 2021-04-03 06:21
  • 閲讀 ( 47 )

如何取消或刪除windows中的卡滯列印作業

...個或多個文件,看看這是否能讓事情重新開始。 這應該可以在WindowsVista、7、8和10中使用。 清除並重新啟動列印後臺處理程式 清除和重新啟動列印後臺處理程式應該是您嘗試修復卡住的列印作業時的第一步,因為它實際上不會...

  • 發佈於 2021-04-08 10:26
  • 閲讀 ( 54 )

如何重新啟動windows的資源管理器.exe(連同工作列和“開始”選單)

...中的任何一個都可能開始奇怪地執行,甚至掛起。就像您可以關閉和重新啟動一個正在執行的應用程式一樣,您也可以關閉並重新啟動Windows資源管理器。如果您剛剛安裝了一個新應用程式或應用了通常需要重新啟動PC的登錄檔調...

  • 發佈於 2021-04-08 10:35
  • 閲讀 ( 34 )

如何在windows上編寫批處理指令碼

你知道如何使用命令提示符嗎?如果你這樣做了,你可以寫一個批處理檔案。在最簡單的形式中,批處理檔案(或批處理指令碼)是雙擊檔案時執行的多個命令的列表。批處理檔案可以一直返回到DOS,但仍然適用於現代版本的Wi...

  • 發佈於 2021-04-09 10:18
  • 閲讀 ( 33 )

如何在windows10上建立和執行bashshell指令碼

...,可以直接使用Bash-c命令執行Bash命令。 例如,要在命令提示符或PowerShell視窗中執行Linux命令,可以執行以下命令: bash -c "command" 這個技巧允許您將Bash命令新增到批處理檔案或PowerShell指令碼中。Bash命令執行時,將出現bashshell視...

  • 發佈於 2021-04-09 10:54
  • 閲讀 ( 48 )

如何在windows10上從bashshell外部執行linux命令

...式。 由於bash-c命令,這是可能的。使用它可以透過命令提示符和PowerShell執行Linux命令,甚至可以建立桌面快捷方式,在啟動時執行Linux命令或程式。 更新:如果安裝了多個Linux環境,可以使用wslconfig命令選擇預設的Linux環境。還...

  • 發佈於 2021-04-09 11:07
  • 閲讀 ( 45 )

如何在windows 10上的新虛擬機器中開啟應用程式或檔案

...個選項,以便在新的虛擬機器中開啟檔案或資料夾,請在提示符處鍵入以下命令,然後按“Enter”。 vdesk -install 單擊命令提示視窗右上角的“X”按鈕將其關閉。 要在新虛擬機器中開啟檔案或程式,請右鍵單擊檔案、program.exe檔...

  • 發佈於 2021-04-09 12:20
  • 閲讀 ( 44 )
q957709418
q957709418

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦