redirect error input stream from runtimeprocess to logger.error
package exec;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -9,9 +12,6 @@ import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.stream.Stream;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class ExecUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ExecUtils.class);
@@ -25,9 +25,26 @@ public class ExecUtils {
if (env != null) {
processBuilder.environment().putAll(env);
}
- processBuilder.redirectErrorStream(true);
+ processBuilder.redirectErrorStream(false);
Process process = processBuilder.start();
+ executorService.submit(
+ () -> {
+ try (BufferedReader reader =
+ Stream.of(process.getErrorStream())
+ .map(InputStreamReader::new)
+ .map(BufferedReader::new)
+ .findAny()
+ .get()) {
+
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ LOGGER.error("Exec error data : {}", line);
+ }
+ }
+ return null;
+ });
+
executorService.submit(
() -> {
try (BufferedReader reader =
@@ -39,7 +56,7 @@ public class ExecUtils {
String line = null;
while ((line = reader.readLine()) != null) {
- LOGGER.debug("Exec : {}", line);
+ LOGGER.debug("Exec line data : {}", line);
}
}
return null;
@@ -58,6 +75,8 @@ public class ExecUtils {
return process;
}
+
+
public static void kill(String pid) throws IOException, InterruptedException {
List<String> args = Arrays.asList("kill", pid);
