I'd like a Java program that I'm working on to be able to run other Java programs. Using Runtime.exec("java ...") seems like the most obvious way to do it, but I can't figure out how to capture the output from the program, or get input to its System.in.
The "best" workaround I've found is to use Reflection to load the Method object for the other program's main(), then use Method.invoke() to run it. The problem is, if the other program ever, say, calls System.exit(), it'll end up exiting *my* program. Likewise, if it changes the Look and Feel, it'll probably change the Look and Feel of my program. So, this is do-able, but not particularly safe.
Would it be possible to use Runtime.exec(), and have something like a JTextArea act as a console? None of my attempts at that have worked; the best I've been able to do is get the output after the program exits, which isn't especially useful for interactive programs.
Has anyone got any other ideas?
The "best" workaround I've found is to use Reflection to load the Method object for the other program's main(), then use Method.invoke() to run it. The problem is, if the other program ever, say, calls System.exit(), it'll end up exiting *my* program. Likewise, if it changes the Look and Feel, it'll probably change the Look and Feel of my program. So, this is do-able, but not particularly safe.
Would it be possible to use Runtime.exec(), and have something like a JTextArea act as a console? None of my attempts at that have worked; the best I've been able to do is get the output after the program exits, which isn't especially useful for interactive programs.
Has anyone got any other ideas?