process.waitFor() does not end

428
March 06, 2017, at 9:13 PM

I have a JAVA code where I am executing a perl script. Some scripts donot return a response code but require passwords for execution. My code does not return in those cases and process.waitFor() endlessly waits. Is there a way I can handle this?

Process process = pb.start();
            int returnCode = process.waitFor();
            System.out.print("return code>>"+ returnCode );

My code has the objective to run the command and show the response code.

Answer 1

I see two choices here:

  • you can manage correctly stdin of the process by getting its OutputStream through Proecess::getOutputStream so that you can correctly send input and let the process finish
  • you can destroy the process (see Process::destroy or Process::destroyForcibly) but this implies that you must choose a maximum amount of time to wait before doing so (and could create problems since you are actually trying to kill a process maybe in the middle of some operation)
READ ALSO
web service call using stub in java [on hold]

web service call using stub in java [on hold]

I have following wsdl http://europeipx

380
Swing: how to intercept when Component isDisplayable() become false

Swing: how to intercept when Component isDisplayable() become false

My scenario: I have some JEditorPane registered to a ObjectManager to do things such like:

327
SETNX returning false even if value is inserted in redis cache

SETNX returning false even if value is inserted in redis cache

As value is inserted,SETNX should return trueCan anyone please help with this ?

426