I have a BAT file to run one of my applications but every time I double click on the BAT file it instantly closes. What can I add to the BAT file to keep it up?
Printable View
I have a BAT file to run one of my applications but every time I double click on the BAT file it instantly closes. What can I add to the BAT file to keep it up?
Post the bat file content and say if your app works ok by clicking twice over the exe fileQuote:
The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved
The BAT works and runs the application. That is not my concern. I want to keep the BAT file up so I can see the output on the black command line screen. I can run the BAT file by running cmd.exe and that will keep the BAT file up but I want to just be able to double click on the BAT file in the directory and not have to go to the command prompt.
Add this command in the BAT file:
Pause > Nul
Yep, Pause will cause it to wait for a key press.
I would probably add a line before the pause like
@Echo Press any key to close
Pause works but not @Echo
Pause by itself will display:
Press any key to continue . . .
> means redirect the output of the preceding command to the succeeding command, which in the previous example will redirect the Press any key to continue . . . to the Nul device. The Nul device is a blackhole - it swallows everything fed into it and displays nothing else.
@Echo Press any key to close will display Press any key to close
... Been a while since I've did a bat file
The console output highly depends on the used commands itselves.Quote:
The BAT works and runs the application. That is not my concern. I want to keep the BAT file up so I can see the output on the black command line screen. I can run the BAT file by running cmd.exe and that will keep the BAT file up but I want to just be able to double click on the BAT file in the directory and not have to go to the command prompt.
Some commands produce an output, some not.
Additionally in some cases its important if you use a batch with bat or cmd extension.
There are some command resource restrictions for bat files.
I would suggest to rename your batch to a cmd file (xyz.cmd).
For example type "dir /b /s" (without doublequotes) will output any files and (sub-)folders under the current directory.
Try to add this as first command in you bat file and output should be visible.
If so any "error" may be caused by the following commands or the commands itself does not produce any output.
One testing example that should work for bat and cmd files:
In cases a batch immediately closes after execution you might do following steps to "debug" errors.Code:@ECHO OFF
DIR /b /s
PAUSE & EXIT
REM Replace first line with ON to view any written content in your batch. Echo off only shows output of commands that produce any output
REM To write more than one command into one line use the ampersand. You could write: Dir /b /s &PAUSE&EXIT
REM Replacing PAUSE&EXIT with PAUSE>NUL & EXIT would supress the Press any key prompt
:: Commenting could be done bei REM which slows down code intensive batches. In most cases :: is the better choice
1st open a command window manually in the same directory of your batch.
2nd type in "cmd /k NameOfYourBatch" and you will see any error output before your script closes.
3rd type "exit" to close console