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?
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?
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
When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day
Post the bat file content and say if your app works ok by clicking twice over the exe fileThe better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved
JG
... If your problem is fixed don't forget to mark your threads as resolvedusing the Thread Tools menu ...
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.
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
When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day
Add this command in the BAT file:
Pause > Nul
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
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
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
When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day
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
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
... Been a while since I've did a bat file
The console output highly depends on the used commands itselves.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