简体   繁体   中英

How to avoid automatic closing of command prompt when double click on .bat file in windows

I have the following commands in my .bat file and when I double click on it command prompt is closing without executing the command.

cd / 
d: 
cd /projects/APP/branch 
rails s

I have a alternate solution for it. when I drag the .bat file to command prompt to press ENTER it works fine, but I need execute it through double click.

Add pause command at the last line of your .bat file.

Win32 console window is closed when the commands running inside it exits, and this cannot be changed.

Add these two lines at the end of your .CMD or .BAT file:

ECHO Press any key to close this window.
PAUSE

This is another alternative solution that worked for me, since I had problems with PAUSE and other commands not working.

echo MSGBOX "Voila!" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q

It will create a temporary .vbs file that will popup with a message, and the command prompt will not close. If you click "OK" on the popup, the command prompt will close and the .vbs file will be deleted.

Wierd way of doing it maybe but I am using it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM