Catching exceptions in external programs

J

Jason

Hi,

I've written a java program which launches a seperate .exe file using
Runtime.getRuntime().exec("<path to executable>"). This executable
tends to be buggy so I'd like to catch exceptions it creates
(exceptions, memory errors, etc... not just stuff it writes to stderr)
and then write these to a log file.
Is this possible?

Thanks in advance,

Jason
 
S

Steve W. Jackson

:Hi,
:
:I've written a java program which launches a seperate .exe file using
:Runtime.getRuntime().exec("<path to executable>"). This executable
:tends to be buggy so I'd like to catch exceptions it creates
:(exceptions, memory errors, etc... not just stuff it writes to stderr)
:and then write these to a log file.
:Is this possible?
:
:Thanks in advance,
:
:Jason

In pure Java? Extremely unlikely.

= Steve =
 
J

John C. Bollinger

Jason said:
I've written a java program which launches a seperate .exe file using
Runtime.getRuntime().exec("<path to executable>"). This executable
tends to be buggy so I'd like to catch exceptions it creates
(exceptions, memory errors, etc... not just stuff it writes to stderr)
and then write these to a log file.
Is this possible?

Not in pure Java, as such. If the external program were another Java
program, then you could run it by invoking its main class'
main(String[]) method, and then you could catch whichever exceptions and
errors you wanted in the normal Java way, but you would have to put up
with the buggy program running in the same VM as the launcher.
Alternatively, you could start it in another VM and connect to that via
the debugging interface.

But if the external program is a native one, then you need to use native
facilities to do what you want. You could access these through JNI, if
you really need a Java facade over the top.


John Bollinger
(e-mail address removed)
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top