I have a Java web application that runs a .bat file (shell script) on an AIX box. The .bat file has a command that runs the executable of a product called Antenna House which generates .pdf files.
Antenna House has its own Java classes, including some that generate specific error messages if the PDF generation fails.
I'm interested in how any error messages generated by Antenna House might be returned to the application while running a .bat file.
Thanks.
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
posted
0
A Java program can return an exit code, which a script in Windows, Unix or Mac (and others probably) can access. I believe it's called the "error level" in a Windows batch file. Vague recollection of it being %ERRORLEVEL% ?
To return an exit code from Java, you must use System.exit(int).
Note that calling System.exit() is bad form, most of the time. If there is any chance that the code you write now might be incorporated in some bigger system (e.g. an application server) later, don't do it. No, really. It kills the whole JVM, even if your code is only a small part of what that JVM is doing.
One alternative to returning an exit code include writing some information to a file, which your script can then read. I'm sure there are other alternatives.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
posted
0
Oh, did I misunderstand? Do you want to see the exit code of a script that you ran from your Java program?
If so, look at Process.exitValue(). The Process object is the thing you got from Runtime.exec() or from ProcessBuilder. [ August 23, 2007: Message edited by: Peter Chase ]
Michael Scott
Ranch Hand
Joined: Jan 20, 2003
Posts: 57
posted
0
Thanks for the feedback. I'm interested in being able to capture the specific error message generated by Antenna House when the .bat file is run - not just a return code. For example, might there be some way of directing the message to a text file on the server. If so, then I'll presume that the application could read this file. [ August 23, 2007: Message edited by: Michael Scott ]
Michael Scott
Ranch Hand
Joined: Jan 20, 2003
Posts: 57
posted
0
This seems to work ... append the following to the command in the .bat file: