Job CmdExec Step Troubles... How do I set exit code from batch file?

  • Hey!

    I have a CmdExec step in my backup job that uses RoboCopy to copy backup files across our network after they are backed up locally.

    My problem is that Robocopy has about 4 return codes that I would consider as successful.

    I built a batch file that catches the errorlevels, and resets the ERRORLEVEL to 0 for the ones I consider as successful, and 1 for ones that I consider as failed.  It works perfectly when I execute it at the command line.

    My issue is that the Job seems to be getting an exit code from somewhere else... nomatter what I set the ERRORLEVEL to in the batch file, the Job gets 0 back.

    Any Idea how I can get back the exit level that I want?


    Kindest Regards,

  • Hey!

    Well, I figured it out... I guess you need to have:

    exit [/b] [ExitCode]

    As the last line of the batch file.

    Works like a charm!


    Kindest Regards,

  • Hey Paul,

    I am attempting to setup a similiar process. If you wouldn't mind, can you post the code you used to make this work?

  • Wow, 5 years later! :w00t:

    The batch file that does the copying should look something like this:

    ----

    ECHO OFF

    C:\Robocopy D:\FOLDER \\REMOTESERVER\FOLDER /MIR /R:10

    ECHO ERRORLEVEL = %errorlevel%

    if errorlevel 16 exit /b 16

    if errorlevel 15 exit /b 15

    if errorlevel 14 exit /b 14

    if errorlevel 13 exit /b 13

    if errorlevel 12 exit /b 12

    if errorlevel 11 exit /b 11

    if errorlevel 10 exit /b 10

    if errorlevel 9 exit /b 9

    if errorlevel 8 exit /b 8

    if errorlevel 7 exit /b 0

    if errorlevel 6 exit /b 0

    if errorlevel 5 exit /b 0

    if errorlevel 4 exit /b 0

    if errorlevel 3 exit /b 0

    if errorlevel 2 exit /b 0

    if errorlevel 1 exit /b 0

    if errorlevel 0 exit /b 0

    :end

  • Thanks for your code. You have no idea how useful this was to me. Although I'm from the DOS world in the 80's, I have forgotten the commands after almost 30 years! But thanks for your post, it made it easy for me.

    Regards,

    MR

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply