Hi,
I'm a project manager and a developer in my team is writing some java
code to run an exe that is part of a vendor application we are
implementing. The developer is claiming there is problems with the
vendors exe as it just return the value 259 constantly for exitValue -
even when he can see it's finished i.e. it hangs returning this value
in his code when he can see it's done. The exe sits on a Windows 2003
server and the code snippet is:
// Runs the batch job
Process p = Runtime.getRuntime().exec("path-to\vendor-app.exe
-batch=EXEQHOLD");
// Cause the current Thread to wait until an exit value is returned.
// The convention for normal termination is zero
int exitValue = p.waitFor();
I was a programmer in a past life but not java but my gut feeling is
that maybe we should be more thorough with this before we go back to
blaming the vendor. Can anyone comment on this or suggest a better way
to launch an exe and wait for it in code to finish?
Many thanks,
s
Larry Barowski - 16 Feb 2006 23:30 GMT
> Hi,
>
[quoted text clipped - 8 lines]
> that maybe we should be more thorough with this before we go back to
> blaming the vendor. ...
Just run the program from the command prompt and check
the exit value (echo %ERRORLEVEL%). If it is always 259,
then the problem is not yours.
John C. Bollinger - 17 Feb 2006 05:40 GMT
> I'm a project manager and a developer in my team is writing some java
> code to run an exe that is part of a vendor application we are
[quoted text clipped - 16 lines]
> blaming the vendor. Can anyone comment on this or suggest a better way
> to launch an exe and wait for it in code to finish?
If the code you showed is all there is to it then it is a bit
simplistic. It should work if the program doesn't produce *any* output
on its standard output or standard error streams, but may otherwise
block when its I/O buffers fill. (I'm assuming that since it's a batch
job, it doesn't read anything from its standard input.) If the external
program only produces a small amount of output then it might run to
completion, but never exit. To address both of these potential
problems, a Java program should generally arrange to drain any external
process's output concurrently with the process; the data are available
via the Process object's getInputStream() and getErrorStream() methods,
and separate threads should be established to read each.
The return value of Process.exitValue() is undefined until the external
process has terminated. You can block on termination of the process via
Process.waitFor(), as you show in your example code.
--
John Bollinger
jobollin@indiana.edu
Kurt M Peters - 17 Feb 2006 13:09 GMT
Try this web page to understand what he's talking about in terms of "no
output". I'm surprised your programmers wouldn't have seen it themselves
though.
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Regards,
Kurt
> Hi,
>
[quoted text clipped - 22 lines]
>
> s