Skip to content

Commit f12e648

Browse files
authored
Fix exec command (#1593)
* Fix exec command * Fix an intermittent issue - join the thread earlier
1 parent 6298f88 commit f12e648

File tree

1 file changed

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

1 file changed

+8
-10
lines changed

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

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

6666
try {
67-
String stdout = null;
6867
if (isRedirectToOut) {
6968
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();
7469
@SuppressWarnings("resource")
7570
CopyingOutputStream copyOut = new CopyingOutputStream(System.out);
7671
// this makes sense because CopyingOutputStream is an InputStreamWrapper
@@ -88,14 +83,17 @@ public static ExecResult exec(
8883
}
8984

9085
p.waitFor();
91-
92-
// if we have not read the stdout, we do it now
93-
if (stdout == null) {
94-
stdout = read(in.getInputStream());
86+
87+
// we need to join the thread before we read the stdout so that the saved stdout is complete
88+
if (out != null) {
89+
out.join();
90+
out = null;
9591
}
96-
return new ExecResult(p.exitValue(), stdout, read(p.getErrorStream()));
92+
93+
return new ExecResult(p.exitValue(), read(in.getInputStream()), read(p.getErrorStream()));
9794

9895
} finally {
96+
// we try to join again if for any reason the code failed before the previous attempt
9997
if (out != null) {
10098
out.join();
10199
}

0 commit comments

Comments
 (0)