Results 1 to 9 of 9

Thread: Running my project using a BAT file

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Running my project using a BAT file

    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?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Running my project using a BAT file

    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
    Post the bat file content and say if your app works ok by clicking twice over the exe file
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Running my project using a BAT file

    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.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Running my project using a BAT file

    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)

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Running my project using a BAT file

    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

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Running my project using a BAT file

    Pause works but not @Echo


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Running my project using a BAT file

    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)

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Running my project using a BAT file

    ... Been a while since I've did a bat file

  9. #9
    Member
    Join Date
    Dec 2009
    Location
    Germany
    Posts
    54

    Re: Running my project using a BAT file

    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 console output highly depends on the used commands itselves.
    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:
    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
    In cases a batch immediately closes after execution you might do following steps to "debug" errors.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width