How to automatically close cmd window after batch file execution?

后端 未结 8 1522
半阙折子戏
半阙折子戏 2020-11-30 23:47

I\'m running a batch file that has these two lines:

start C:\\Users\\Yiwei\\Downloads\\putty.exe -load \"MathCS-labMachine1\"
\"C:\\Program Files (x86)\\Xmi         


        
相关标签:
8条回答
  • 2020-12-01 00:11

    If you want to separate the commands into one command per file, you can do

    cmd /c start C:\Users\Yiwei\Downloads\putty.exe -load "MathCS-labMachine1"
    

    and in the other file, you can do

    cmd /c start "" "C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow
    

    The command cmd /c will close the command-prompt window after the exe was run.

    0 讨论(0)
  • 2020-12-01 00:11

    This worked for me. I just wanted to close the command window automatically after exiting the game. I just double click on the .bat file on my desktop. No shortcuts.

    taskkill /f /IM explorer.exe
    C:\"GOG Games"\Starcraft\Starcraft.exe
    start explorer.exe
    exit /B
    
    0 讨论(0)
  • 2020-12-01 00:20

    Add this code at the end of the execution code

    c:\windows>exit

    0 讨论(0)
  • 2020-12-01 00:24

    Just try /s as listed below.

    As the last line in the batch file type:

    exit /s
    

    The above command will close the Windows CMD window.

    /s - stands for silent as in (it would wait for an input from the keyboard).

    0 讨论(0)
  • 2020-12-01 00:25

    I had this, I added EXIT and initially it didn't work, I guess per requiring the called program exiting advice mentioned in another response here, however it now works without further ado - not sure what's caused this, but the point to note is that I'm calling a data file .html rather than the program that handles it browser.exe, I did not edit anything else but suffice it to say it's much neater just using a bat file to access the main access pages of those web documents and only having title.bat, contents.bat, index.bat in the root folder with the rest of the content in a subfolder.

    i.e.: contents.bat reads

    cd subfolder
    "contents.html"
    exit
    

    It also looks better if I change the bat file icons for just those items to suit the context they are in too, but that's another matter, hiding the bat files in the subfolder and creating custom icon shortcuts to them in the root folder with the images called for the customisation also hidden.

    0 讨论(0)
  • 2020-12-01 00:26

    Modify the batch file to START both programs, instead of STARTing one and CALLing another

    start C:\Users\Yiwei\Downloads\putty.exe -load "MathCS-labMachine1"
    start "" "C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow
    

    If you run it like this, no CMD window will stay open after starting the program.

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