mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: CommandExecutor refactoring
parent
7d6cbeb049
commit
c44c3cdd76
|
@ -22,6 +22,9 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pablo Fuente (pablofuenteperez@gmail.com)
|
||||||
|
*/
|
||||||
public class CommandExecutor {
|
public class CommandExecutor {
|
||||||
|
|
||||||
public static String execCommand(String... command) throws IOException, InterruptedException {
|
public static String execCommand(String... command) throws IOException, InterruptedException {
|
||||||
|
@ -40,23 +43,34 @@ public class CommandExecutor {
|
||||||
String... command) throws IOException, InterruptedException {
|
String... command) throws IOException, InterruptedException {
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder(command).redirectOutput(standardOutputFile)
|
ProcessBuilder processBuilder = new ProcessBuilder(command).redirectOutput(standardOutputFile)
|
||||||
.redirectError(errorOutputFile);
|
.redirectError(errorOutputFile);
|
||||||
commonExecCommand(processBuilder);
|
Process process = processBuilder.start();
|
||||||
|
process.waitFor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String commonExecCommand(ProcessBuilder processBuilder) throws IOException, InterruptedException {
|
private static String commonExecCommand(ProcessBuilder processBuilder) throws IOException, InterruptedException {
|
||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
StringBuilder processOutput = new StringBuilder();
|
StringBuilder processOutput = new StringBuilder();
|
||||||
|
String output;
|
||||||
try (BufferedReader processOutputReader = new BufferedReader(
|
InputStreamReader inputStreamReader = null;
|
||||||
new InputStreamReader(process.getInputStream()));) {
|
BufferedReader processOutputReader = null;
|
||||||
|
try {
|
||||||
|
inputStreamReader = new InputStreamReader(process.getInputStream());
|
||||||
|
processOutputReader = new BufferedReader(inputStreamReader);
|
||||||
String readLine;
|
String readLine;
|
||||||
while ((readLine = processOutputReader.readLine()) != null) {
|
while ((readLine = processOutputReader.readLine()) != null) {
|
||||||
processOutput.append(readLine + System.lineSeparator());
|
processOutput.append(readLine + System.lineSeparator());
|
||||||
}
|
}
|
||||||
process.waitFor();
|
process.waitFor();
|
||||||
|
output = processOutput.toString().trim();
|
||||||
|
} finally {
|
||||||
|
if (inputStreamReader != null) {
|
||||||
|
inputStreamReader.close();
|
||||||
|
}
|
||||||
|
if (processOutputReader != null) {
|
||||||
|
processOutputReader.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return processOutput.toString().trim();
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue