exit code capture not working

mneder (5 posts)
April 8, 2009 02:06 PM
Accepted Answer

Hello,

 

I am using adTempus v3.0.4 and I am seeing an issue with it no recognizing the exit code.  I verified that after the java program execute it returns an exit code by using the ERRORLEVEL variable in the batch.  But after I remove the ERRORLEVEL variable and leave the java as the last line in the batch, adTempus always reports an exit code of 1, no matter what exit code was actually returned.  Is there a setting in adTempus that I am overlooking?

 

Thanks in advance.

Bill Staff (604 posts)
April 8, 2009 03:29 PM
Accepted Answer

To return an exit code from a Java program, your program must terminate using System.exit. If you don't do that, the exit code is set by the Java virtual machine and has nothing to do with the outcome of your program.

When you run a batch file, the exit code that gets passed back to adTempus by Windows is the exit code of the last command that executes in the batch file. So you also need to make sure that nothing else is happening in the batch file after you run the Java program.

This includes statements like "echo": if you have an echo statement, the echo itself will return an exit code of 0, which will become the new exit code for the batch file.

How are you testing the exit code from the java program? Please post the relevant portion of your batch file. It may be that you are testing the result incorrectly, and inadvertently resetting the exit code to 0 while doing so.

An exit code of 1 from java generally means there's an error. You should capture the console output from your batch file and check for error messages.


mneder (5 posts)
April 9, 2009 09:14 AM
Accepted Answer

Hi there,

Thank you for your response.  Actually I have done everything you describe in your reply.  I was under the assumption that I had to look for a configuration option in adTempus to make it recognize exit codes. 

 Here is my java code with job I am making specifically to test exit codes with adTempus - 

     public static void main(String[] args) {
        // TODO code application logic here
        try{
            File file = new File ("C:\\faotest\\test.txt");
            if (!file.exists()) {
                // System.out.println(1);
                System.exit(10);
            }
            else {
               // System.out.println(0);
                System.exit(20);
            }
        }
        catch(Throwable t){
            t.printStackTrace();
        }
    }

 

here is the batch file contents -

 CD D:\faoexit
java faoexit

This unfortunately doesn't pass the exit code to adTempus. However if I where to put in a third like such as echo %ERRORLEVEL% the correct error code prints out.  If I remove the echo it should pass the exit code to adTempus, at least I understand that it should.  Is there something in adTempus that has to be changed?

Thank you kindly

Bill Staff (604 posts)
April 9, 2009 10:50 AM
Accepted Answer

I tested with your code and everything worked correctly. What exit code are you seeing in adTempus, and where are you looking? If you display the details for an instance, the Steps page will list the Result, which is the exit code from the batch file.

Did you try capturing the console output to see if there are any error messages being dumped to the console?

Some observations:

  • Your code will return exit code 10 (not found) or 20 (file found), but it will return a 0 if there is an exception.
  • If something goes wrong before your code is executed, like a missing class or something, I'm not sure what result you'll get. When I tested it I got a 0 in that case, but we've had other customers report an exit code 1 in similar scenarios.
  • If you put an echo statement in your batch file, that resets the exit code of the batch file to 0. So if you have an echo as your last statement, it will print out the correct exit code, but adTempus will get a 0.
You should uncomment your println statements, recompile, and run this with "Capture Console" so we can see exactly what's happening.

 


mneder (5 posts)
April 9, 2009 12:52 PM
Accepted Answer

Hi Bill,

I have already tested by uncommenting those println statements.  I also indeed don't have an echo line at the end.  I only put it there when I want to capture the exit code in the command line.  Then I remove it when using the batch with adTempus.

This was tested a month ago by another developer and he determined that adTempus has the issue.  He is no longer with us and I am now following up.  I am using my engineering background and have concluded that there is nothing wrong with the batch and/or java file. 

The exit code that adTempus is capturing shows to be 1. This is what it says, "Step failed because the program run by adTempus returned an exit code of 1, which indicates failure. Consult the documentation or output from the program for information on the meaning of this exit code."

No matter what the exit actually is, whether 10 or 20 or 30, etc., adTempus always thinks the exit code is 1.

 

Bill Staff (604 posts)
April 9, 2009 12:54 PM
Accepted Answer
Please capture the console output when you run the job and post the output.
mneder (5 posts)
April 9, 2009 01:10 PM
Accepted Answer

Here is my console when I run the batch file in a command prompt -

D:\jobs\bin>faoexit

D:\jobs\bin>CD D:\faoexit

D:\faoexit>java faoexit

D:\faoexit>

And here is my console when I add this to the last line in the batch - echo "exit code = " %ERRORLEVEL%

 D:\jobs\bin>faoexit

D:\jobs\bin>CD D:\faoexit

D:\faoexit>java faoexit

D:\faoexit>echo "exit code = " 10
"exit code = " 10

D:\faoexit>

As you can see, the exit code is supposed to me 10.  If I remove the echo line and run it in adTempus, i get a failed message saying that adTempus thinks the exit code is 1


Bill Staff (604 posts)
April 9, 2009 01:15 PM
Accepted Answer
I want to see the console output when adTempus runs the batch file, not the output you get when you run it from the command prompt. Edit your step and set the Window Mode to "Capture Console", then post the captured output from the job history.
mneder (5 posts)
April 9, 2009 02:35 PM
Accepted Answer

Hi Bill,

I am still doing some testing to be sure but I think I got it.  When I was going to send you the output from adTempus I went to the steps configuration tab first and found a disk drive mentioned that does not exist on this server.  The execution directory was wrong and pointing to a B: drive with is not on this server.  I am not sure if it was an error by the folks that originally set this up or if the disk drives since changed.  I will let you know if I have any further questions.  I appreciate your help.

Thanks a million,

Michael

Replies are disabled for this topic.