ProcessBuilder : notification to java from the external executable

S

slightlykirix

Hi,
I have a class that is supposed to call an executable fortran file that
create some additional fortran files, and then compile them. I am
performing the call to the fortran executable and the compilation steps
through the use of the ProcessBuilder.
My question is, suppose any one of the steps fail, how can java be made
aware that something has gone wrong?
For eg, when i call the fortran executable, if the fortran executable
encounters a problem, it may not produce the additional fortran files.
So, java should be notified that the next steps - calling the compiler
should not be done.
My understanding of the ProcessBuilder was that it just creates an
environment for an executable and doesn't really track what the
executable does - whether it does what it is supposed to do, or fails.
I was thinking of tracking the output of the executable with the
redirectErrorStream() and then checking to see if the stream ends with
what one would expect with an error-free run.
Is that the most elegant approach or is there something else that I am
totally missing?
TIA
--Jo
 
O

Oliver Wong

slightlykirix said:
Hi,
I have a class that is supposed to call an executable fortran file that
create some additional fortran files, and then compile them. I am
performing the call to the fortran executable and the compilation steps
through the use of the ProcessBuilder.
My question is, suppose any one of the steps fail, how can java be made
aware that something has gone wrong?
For eg, when i call the fortran executable, if the fortran executable
encounters a problem, it may not produce the additional fortran files.
So, java should be notified that the next steps - calling the compiler
should not be done.
My understanding of the ProcessBuilder was that it just creates an
environment for an executable and doesn't really track what the
executable does - whether it does what it is supposed to do, or fails.
I was thinking of tracking the output of the executable with the
redirectErrorStream() and then checking to see if the stream ends with
what one would expect with an error-free run.
Is that the most elegant approach or is there something else that I am
totally missing?

If the Fortran program uses return values or error codes, you might be
able to check those. Otherwise, your approach sounds about right. The way
I'd go about solving this problem is asking how I, as a human being, would
know if the process succeeded or failed (perhaps checking for the existence
of the generated Fortran files if you know their names ahead of time?).
Then, assuming that the "algorithm" that I use is tractable, write the
program to do the same thing.

- Oliver
 
R

Roedy Green

My question is, suppose any one of the steps fail, how can java be made
aware that something has gone wrong?

Each step returns an exit code. Presumably the commend interpreter
also returns an exit code.
 
R

Roedy Green

Each step returns an exit code. Presumably the commend interpreter
also returns an exit code.
Alternatively you spawn each step directly from java and examine its
return code.
 
O

Oliver Wong

Roedy Green said:
Each step returns an exit code. Presumably the commend interpreter
also returns an exit code.

Without seeing the actual Fortran source code, or running the program
yourself as a test, you can't actually know this for sure. Or more
accurately, perhaps the return code that the Fortran program returns does
not contain any meaningful information (e.g. it is always 0, whether the
step succeeded or not).

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top