33 Votes

Batch-Script: CMD Window should remain open after Program Run

Question by CSchaf | Last update on 2023-01-20 | Created on 2014-09-04

I have written a small batch script that is calling and executing a program. This application is writing some information into the console (I mean the black CMD or command line interpreter window that is opened when clicking on a BAT-file).

My problem is that Windows automatically closes that window, so that I can not see the output of my program. I have already tried to take a screenshot exactly at the moment the window shortly pops up, but this is not a good solution.

Is there any possibility to keep the command prompt window open and not to close it automatically?

ReplyPositiveNegativeDateVotes
4Best Answer4 Votes

You can just use the command "pause".

For example in the following way:

@echo off
prog.exe
pause

This batch script executes the program "prog.exe" and as soon as the script comes across the line "pause", it stops. Then, the message "Please press any key..." is displayed and only after pressing a key, the script will be resumed and with this the window is closed.

Using this command, you should be able to read the output of the program without any problems.
Last update on 2023-01-20 | Created on 2014-09-04

ReplyPositive Negative
00 Votes

You could also do that as an example:

@echo off
@echo Hello
timeout 7

The command "timeout" will then stop the script for the specified time (here for 7 seconds).
2022-10-30 at 20:49

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.