Skip to content

Commit d7c4314

Browse files
authored
Fix command stdout (#1587)
* Fix ExecCommand to allow both redirect and saveResults enabled the same time * minor cleanup
1 parent e747e71 commit d7c4314

File tree

1 file changed

+12
-1
lines changed
  • new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils

1 file changed

+12
-1
lines changed

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ public static ExecResult exec(
6464
Thread out = null;
6565

6666
try {
67+
String stdout = null;
6768
if (isRedirectToOut) {
6869
InputStream i = in.getInputStream();
70+
i.mark(0);
71+
// read the stdout first, and reset before we redirect the output
72+
stdout = read(i);
73+
i.reset();
6974
@SuppressWarnings("resource")
7075
CopyingOutputStream copyOut = new CopyingOutputStream(System.out);
7176
// this makes sense because CopyingOutputStream is an InputStreamWrapper
@@ -83,7 +88,13 @@ public static ExecResult exec(
8388
}
8489

8590
p.waitFor();
86-
return new ExecResult(p.exitValue(), read(in.getInputStream()), read(p.getErrorStream()));
91+
92+
// if we have not read the stdout, we do it now
93+
if (stdout == null) {
94+
stdout = read(in.getInputStream());
95+
}
96+
return new ExecResult(p.exitValue(), stdout, read(p.getErrorStream()));
97+
8798
} finally {
8899
if (out != null) {
89100
out.join();

0 commit comments

Comments
 (0)