In the following example, the console gets all the output, but the String output value remains empty:
String output = new ProcessExecutor().command("java", "-version")
.redirectError(Slf4jStream.of(getClass()).asInfo())
.readOutput(true).execute()
.outputUTF8();
Output:
2021-12-30 12:51:32.150 DEBUG 43928 --- [ XNIO-1 task-1] org.zeroturnaround.exec.ProcessExecutor : Executing [java, -version].
2021-12-30 12:51:32.177 DEBUG 43928 --- [ XNIO-1 task-1] org.zeroturnaround.exec.ProcessExecutor : Started java.lang.UNIXProcess@56e2d396
2021-12-30 12:51:32.296 INFO 43928 --- [ Thread-56] c.l.openmx.service.mapper.AccountMapper : openjdk version "1.8.0_292"
2021-12-30 12:51:32.297 INFO 43928 --- [ Thread-56] c.l.openmx.service.mapper.AccountMapper : OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
2021-12-30 12:51:32.297 INFO 43928 --- [ Thread-56] c.l.openmx.service.mapper.AccountMapper : OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)
2021-12-30 12:51:32.300 DEBUG 43928 --- [ XNIO-1 task-1] org.zeroturnaround.exec.WaitForProcess : java.lang.UNIXProcess@56e2d396 stopped with exit code 0
Without redirectError, the String output gets the output value:
String output = new ProcessExecutor().command("java", "-version")
.readOutput(true).execute()
.outputUTF8();
Output:
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)
Questions:
- Does
redirectError work just in case of errors?
- Should
String output get the output value with redirectError in place?
In the following example, the console gets all the output, but the
String outputvalue remains empty:Output:
Without
redirectError, theString outputgets the output value:Output:
openjdk version "1.8.0_292" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)Questions:
redirectErrorwork just in case of errors?String outputget the output value withredirectErrorin place?