|
4 | 4 | import java.io.IOException;
|
5 | 5 | import java.io.InputStreamReader;
|
6 | 6 | import java.io.PrintWriter;
|
| 7 | +import java.util.HashMap; |
7 | 8 | import java.util.Map;
|
8 | 9 |
|
9 | 10 | import oracle.weblogic.deploy.logging.PlatformLogger;
|
@@ -54,12 +55,27 @@ public static CommandResult run(String command) throws IOException, InterruptedE
|
54 | 55 | * @throws InterruptedException if the wait is interrupted before the process completes
|
55 | 56 | */
|
56 | 57 | public static CommandResult run(String command, PrintWriter output) throws IOException, InterruptedException {
|
| 58 | + return run(command, output, new HashMap<>()); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Run the provided shell command, and send stdout/stderr to the PrintWriter. |
| 63 | + * @param command external command to be executed |
| 64 | + * @param output PrintWriter to receive stdout |
| 65 | + * @param environment values to insert into the new process environment |
| 66 | + * @return result from running the provided command |
| 67 | + * @throws IOException if process start fails |
| 68 | + * @throws InterruptedException if the wait is interrupted before the process completes |
| 69 | + */ |
| 70 | + public static CommandResult run(String command, PrintWriter output, Map<String,String> environment) throws IOException, InterruptedException { |
57 | 71 | ProcessBuilder pb = new ProcessBuilder("/bin/sh", "-c", command);
|
58 | 72 | Process p = null;
|
59 | 73 |
|
60 | 74 | try {
|
61 | 75 | pb.redirectErrorStream(true);
|
62 | 76 | p = pb.start();
|
| 77 | + Map<String, String> processEnv = pb.environment(); |
| 78 | + processEnv.putAll(environment); |
63 | 79 |
|
64 | 80 | BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8));
|
65 | 81 | StringBuilder processOut = new StringBuilder();
|
|
0 commit comments