Skip to content

redirectError example is confusing #100

@micobarac

Description

@micobarac

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:

  1. Does redirectError work just in case of errors?
  2. Should String output get the output value with redirectError in place?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions