Re: Better way to do error handling here?
laredotornado wrote:
I'm using Java 1.5. At a certain point in my program, I have this
code:
phpProcess = Runtime.getRuntime().exec(phpNormalizerCommand);
stdoutReader =
new BufferedReader
(new InputStreamReader(phpProcess.getInputStream()));
stdinWriter =
new PrintWriter
(new OutputStreamWriter(phpProcess.getOutputStream()));
Later I use the stdoutReader and stdinWriter variables. The
"phpNormalizerCommand" variable runs a script that depends on PHP.
However, if PHP is not installed on the machine, the command would
normally print
/usr/bin/php5: bad interpreter: No such file or directory
from a termianl . Is there some way after first ilne of the code above
that I could trap for this error and stop my program if I detect such
an error?
Other have already discussed the funny world of Runtime exec.
But instead of running PHP as an external executable, then you could
consider running the PHP code inside the JVM. Both Caucho and IBM
has created products to allow that.
Arne