Honus Wagner
Honus Wagner

Reputation: 2908

DOS CMD send failure to Autosys

In Autosys, I have a job that executes a fairly simple DOS batch file (.CMD). How do I communicate back to Autosys if the job has conditionally failed? If it runs and terminates, Autosys reports a success no matter what. I would like to programmatically tell Autosys if the script failed based on conditions determined within.

Any help would be appreciated. Thanks in advance.

Upvotes: 1

Views: 4257

Answers (2)

Justin
Justin

Reputation: 11

What you need to do is the last line of your .bat file should say the following:

EXIT /B %ErrorLevel%

Upvotes: 1

NickT
NickT

Reputation: 23873

You can use ERRORLEVEL, open a DOS box and type 'help if' These bits are relevant:

C:\help if
Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

  NOT               Specifies that Windows should carry out
                    the command only if the condition is false.

  ERRORLEVEL number Specifies a true condition if the last program run
                    returned an exit code equal to or greater than the number
                    specified.


%ERRORLEVEL% will expand into a string representation of
the current value of ERRORLEVEL, provided that there is not already
an environment variable with the name ERRORLEVEL, in which case you
will get its value instead.  After running a program, the following
illustrates ERRORLEVEL use:

    goto answer%ERRORLEVEL%
    :answer0
    echo Program had return code 0
    :answer1
    echo Program had return code 1

Upvotes: 2

Related Questions