How do I minimize the command prompt from my bat file

前端 未结 12 798
攒了一身酷
攒了一身酷 2020-12-02 14:15

I have this bat file and I want to minimize the cmd window when I run it:

@echo off
cd /d C:\\leads\\ssh 
call C:\\Ruby192\\bin\\setrbvars.bat
ruby C:\\leads         


        
相关标签:
12条回答
  • 2020-12-02 14:53

    You could try running a script as follows

    var WindowStyle_Hidden = 0
    var objShell = WScript.CreateObject("WScript.Shell")
    var result = objShell.Run("cmd.exe /c setrbvars.bat", WindowStyle_Hidden)
    

    save the file as filename.js

    0 讨论(0)
  • 2020-12-02 14:53

    You can minimize the command prompt on during the run but you'll need two additional scripts: windowMode and getCmdPid.bat:

    @echo off
    
    call getCmdPid
    call windowMode -pid %errorlevel% -mode minimized
    
    cd /d C:\leads\ssh 
    call C:\Ruby192\bin\setrbvars.bat
    ruby C:\leads\ssh\put_leads.rb
    
    0 讨论(0)
  • 2020-12-02 14:54

    Another option that works fine for me is to use ConEmu, see http://conemu.github.io/en/ConEmuArgs.html

    "C:\Program Files\ConEmu\ConEmu64.exe" -min -run myfile.bat
    
    0 讨论(0)
  • 2020-12-02 14:55

    Using PowerShell you can minimize from the same file without opening a new instance.

    powershell -window minimized -command ""
    

    Also -window hidden and -window normal is available to hide completely or restore.


    source: https://stackoverflow.com/a/45061676/1178975

    0 讨论(0)
  • 2020-12-02 14:55

    One option is to find one of the various utilities that can change the window state of the currently running console window and make a call to it from within the batch script.

    You can run it as the first thing in your batch script. Here are two such tools:

    min.exe http://www.paulsadowski.com/wsh/cmdprogs.htm

    cmdow http://www.commandline.co.uk/cmdow/index.html

    0 讨论(0)
  • 2020-12-02 14:58

    If you type this text in your bat file:

    start /min blah.exe
    

    It will immediately minimize as soon as it opens the program. You will only see a brief flash of it and it will disappear.

    0 讨论(0)
提交回复
热议问题