|
|
@ -17,10 +17,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.plugin.alert.script; |
|
|
|
package org.apache.dolphinscheduler.plugin.alert.script; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -41,25 +39,21 @@ public class ProcessUtils { |
|
|
|
public static Integer executeScript(String... cmd) { |
|
|
|
public static Integer executeScript(String... cmd) { |
|
|
|
|
|
|
|
|
|
|
|
int exitCode = -1; |
|
|
|
int exitCode = -1; |
|
|
|
|
|
|
|
|
|
|
|
ProcessBuilder processBuilder = new ProcessBuilder(cmd); |
|
|
|
ProcessBuilder processBuilder = new ProcessBuilder(cmd); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Process process = processBuilder.start(); |
|
|
|
Process process = processBuilder.start(); |
|
|
|
|
|
|
|
|
|
|
|
InputStream in = process.getErrorStream(); |
|
|
|
InputStream in = process.getErrorStream(); |
|
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in)); |
|
|
|
|
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StreamGobbler inputStreamGobbler = |
|
|
|
StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream()); |
|
|
|
new StreamGobbler(process.getInputStream()); |
|
|
|
StreamGobbler errorStreamGobbler = new StreamGobbler(process.getErrorStream()); |
|
|
|
StreamGobbler errorStreamGobbler = |
|
|
|
|
|
|
|
new StreamGobbler(process.getErrorStream()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inputStreamGobbler.start(); |
|
|
|
inputStreamGobbler.start(); |
|
|
|
errorStreamGobbler.start(); |
|
|
|
errorStreamGobbler.start(); |
|
|
|
return process.waitFor(); |
|
|
|
return process.waitFor(); |
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException | InterruptedException e) { |
|
|
|
} catch (IOException | InterruptedException e) { |
|
|
|
logger.error("execute alert script error", e.getMessage()); |
|
|
|
logger.error("execute alert script error {}", e.getMessage()); |
|
|
|
|
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return exitCode; |
|
|
|
return exitCode; |
|
|
|