Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file "IF" error "GoTo" EOF commandline  (Read 5442 times)

0 Members and 1 Guest are viewing this topic.

AccadaccA

    Topic Starter


    Greenhorn

    • Experience: Experienced
    • OS: Windows 7
    Batch file "IF" error "GoTo" EOF commandline
    « on: January 07, 2017, 03:23:03 AM »
    Hi, I didn't know this forum existed until today, how awesome!!
    I'm making a vb6 program which creates and shell executes a batch file.
    The batch file has four commands, three of which are to a game engine required to compile maps.
    The fourth command is to a pop-up exe file I've created to alert the user when the whole process has completed.

    It all works great except when one of the three map compile processes hit a major compile error and the CMD console (DOS box) closes before processing any of the remaining commands.

    I would like to place "If" and "GoTo" conditions to each of the three process commands so that it will go through all four commands normally but also GoTo the fourth command on error.
    Something like...
    If commandline1 errs goto commandline 4
    If commandline2 errs goto commandline 4
    If commandline3 errs goto commandline 4
    commandline 4 (sends pop-up alert)

    Pure and simple, please. I have searched for this all day and everything I have found has gone clear over my head.
    I don't need "If Exists", I know they do (besides I can call that in vb), but most search results I have read on batch file "If"s are "If Exists".

    I do apologize if this is in the wrong forum and understand if it is moved.
    I just saw "DOS" and thought DOS command console. It's actually a Windows/DOS topic. A little from column A, a little from column B.

    Go easy with the guru lingo, I'm old, a long way from the good ol' DOS days and it's my first time here. :)
    Thank you.
    « Last Edit: January 07, 2017, 03:43:40 AM by AccadaccA »

    Salmon Trout

    • Guest
    Re: Batch file "IF" error "GoTo" EOF commandline
    « Reply #1 on: January 07, 2017, 05:34:58 AM »
    The batch file has four commands, three of which are to a game engine required to compile maps.
    Since we are not telepaths, the actual code would make the task of deciding if we can help a lot easier. You can clean up personal references or sensitive stuff.

    AccadaccA

      Topic Starter


      Greenhorn

      • Experience: Experienced
      • OS: Windows 7
      Re: Batch file "IF" error "GoTo" EOF commandline
      « Reply #2 on: January 07, 2017, 06:53:54 AM »
      Sorry, I didn't think that the path and  filename specifics would make a difference.
      Code: [Select]
      "C:\MOHAAT~1\Q3map.exe" -v -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox
      "C:\MOHAAT~1\Q3map.exe" -vis -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox
      "C:\MOHAAT~1\MOHlight.exe" -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox
      "C:\Program Files (x86)\Microsoft Visual Studio\VB98\My Projects\Map Mate\041\done.exe"


      As I said, the batch works well except when error occurs with either stage of the compile (first three command lines)

      Salmon Trout

      • Guest
      Re: Batch file "IF" error "GoTo" EOF commandline
      « Reply #3 on: January 07, 2017, 07:20:39 AM »
      You could check for the exit code from the apps you are running, Q3map.exe and MOHlight.exe, assuming that they give a nonzero exit code when the errors of which you speak occur.

      Do these programs give console output?


      Salmon Trout

      • Guest
      Re: Batch file "IF" error "GoTo" EOF commandline
      « Reply #4 on: January 07, 2017, 08:02:37 AM »
      You could try something like this using the && (zero errorlevel) and || (nonzero errorlevel) tests

      Code: [Select]
      Echo Starting sequence...
      echo Starting task 1 of 3
      "C:\MOHAAT~1\Q3map.exe" -v -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox && (echo OK) || (goto error)
      echo starting task 2 of 3
      "C:\MOHAAT~1\Q3map.exe" -vis -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox && (echo OK) || (goto error)
      echo Starting task 3 of 3
      "C:\MOHAAT~1\MOHlight.exe" -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox && && (echo OK) || (goto error)
      goto done
      :error
      echo ERROR
      :done
      "C:\Program Files (x86)\Microsoft Visual Studio\VB98\My Projects\Map Mate\041\done.exe"

      Salmon Trout

      • Guest
      Re: Batch file "IF" error "GoTo" EOF commandline
      « Reply #5 on: January 07, 2017, 02:36:29 PM »
      Correction (accidentally doubled the &&)

      Code: [Select]
      echo Starting task 3 of 3
      "C:\MOHAAT~1\MOHlight.exe" -fast -gamedir C:\Games\MOHAA C:\Games\MOHAA\main\maps\skybox && (echo OK) || (goto error)

      AccadaccA

        Topic Starter


        Greenhorn

        • Experience: Experienced
        • OS: Windows 7
        Re: Batch file "IF" error "GoTo" EOF commandline
        « Reply #6 on: January 10, 2017, 03:17:36 AM »
        Sorry for not getting back to this sooner, life got in the way.

        Thank  you, I will give that a try.


        edit: Sorry I skipped this..
        .........
        Do these programs give console output?
        Yes, they do, for several minutes.

        AccadaccA

          Topic Starter


          Greenhorn

          • Experience: Experienced
          • OS: Windows 7
          Re: Batch file "IF" error "GoTo" EOF commandline
          « Reply #7 on: January 10, 2017, 05:44:24 PM »
          Whoohoo!!

          It worked perfectly.  Thank you, Salmon Trout.

          Sorry, I don't have any erroneous maps so I had to ask around for some so I could test the bat. lol

          AccadaccA

            Topic Starter


            Greenhorn

            • Experience: Experienced
            • OS: Windows 7
            Re: Batch file "IF" error "GoTo" EOF commandline
            « Reply #8 on: January 10, 2017, 05:46:31 PM »
            I can't see how to mark the thread as "Resolved".