I execute rar command with some file, that i cant attach here
But this problem appear only on that file, in many other - everything ok
Command looks like:
rar x /tmp/junit15696402387580789438/ОС.rar /tmp/junit15696402387580789438
The case:
Process process = new ProcessBuilder(commandArray).start();
try (Reader reader = new InputStreamReader(process.getInputStream())) {
CharStreams.toString(reader);
} catch (Exception e) {
getLogger().error(e);
}
return process.waitFor();
Return 0 code, ok
But if i just replace getInputStream and waitFor, it will execute forever
Code:
Process process = new ProcessBuilder(commandArray).start();
int code = process.waitFor();
try (Reader reader = new InputStreamReader(process.getInputStream())) {
CharStreams.toString(reader);
} catch (Exception e) {
getLogger().error(e);
}
return code;
In method process.waitFor() it will be forever cycle
I set an Thread.sleep(100000), but it do not help
Process process = new ProcessBuilder(commandArray).start();
try {
Thread.sleep(100000);
} catch (InterruptedException e) {
e.printStackTrace();
}
int code = process.waitFor();
try (Reader reader = new InputStreamReader(process.getInputStream())) {
CharStreams.toString(reader);
} catch (Exception e) {
getLogger().error(e);
}
return code;
The process takes little time, just 1-2 seconds in command line
So:
Is it a normal situation, that i must do something with process to get exit code before? I guess, that process must be executed in other thread, and i dont need to yank any additional methods? Why does it happend? Why Process command waitFor() can be forever executed without getInputStream() calling?
Is there a 100% solution, for call exit code, that will not be executed forever?
Can rar utility block somehow getting exit code method?