When I execute a command in a separate process, for example, using the Runtime.getRuntime().exec(...)
method, whose JavaDoc states:
Executes the specified command and arguments in a separate process.
What do I need to do with threads from this process, knowing that the process should work until a Java program exists? (this is a detail, but the Java program will take care of killing this process, and the process itself has built-in protection, where it kills itself if it notices that the Java program that spawned it no longer works).
If we consider that this process does not output at all (for example, because all error messages and stdout are redirected to / dev / null, and all communications are made using files / sockets / something else), what should I do with input stream?
Should I have one (or two?) Java threads running in vain while trying to read stdout / stderr?
What is the right way to handle a long-lived external process spawned from a Java program that does not create stdout / stderr at all?
EDIT
I basically wrap the shell of the script in another shell of the script, which will necessarily redirect everything to / dev / null. I'm sure my Un * x will be incompatible if my shell "outter" script (one redirects everything to / dev / null) still generates something on stdout or stderr. However, I find it reasonable that I would somehow suggest that threads execute during the application’s life-cycle “for nothing.” It really affects the mind.
source share