| 1 |
package net.oni2.aeinstaller.backend; |
| 2 |
|
| 3 |
import java.io.BufferedReader; |
| 4 |
import java.io.File; |
| 5 |
import java.io.IOException; |
| 6 |
import java.io.InputStream; |
| 7 |
import java.io.InputStreamReader; |
| 8 |
import java.util.List; |
| 9 |
import java.util.Vector; |
| 10 |
|
| 11 |
/** |
| 12 |
* @author Christian Illy |
| 13 |
*/ |
| 14 |
public class AppExecution { |
| 15 |
|
| 16 |
/** |
| 17 |
* Execute a short running application and wait for termination |
| 18 |
* |
| 19 |
* @param cmdLine |
| 20 |
* List of command and arguments |
| 21 |
* @return List of output lines |
| 22 |
* @throws IOException |
| 23 |
* Exc |
| 24 |
*/ |
| 25 |
public static Vector<String> executeAndWait(List<String> cmdLine) |
| 26 |
throws IOException { |
| 27 |
ProcessBuilder pb = new ProcessBuilder(cmdLine); |
| 28 |
pb.redirectErrorStream(true); |
| 29 |
Process proc = pb.start(); |
| 30 |
|
| 31 |
InputStream is = proc.getInputStream(); |
| 32 |
InputStreamReader isr = new InputStreamReader(is); |
| 33 |
BufferedReader br = new BufferedReader(isr); |
| 34 |
|
| 35 |
String line; |
| 36 |
Vector<String> lines = new Vector<String>(); |
| 37 |
|
| 38 |
while ((line = br.readLine()) != null) { |
| 39 |
lines.add(line); |
| 40 |
} |
| 41 |
return lines; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Execute an app without waiting |
| 46 |
* |
| 47 |
* @param cmd |
| 48 |
* Command and parameters |
| 49 |
* @param workingDirectory |
| 50 |
* Working directory of app |
| 51 |
*/ |
| 52 |
public static void execute(List<String> cmd, File workingDirectory) { |
| 53 |
try { |
| 54 |
ProcessBuilder pb = new ProcessBuilder(cmd); |
| 55 |
pb.directory(workingDirectory); |
| 56 |
pb.start(); |
| 57 |
} catch (IOException e) { |
| 58 |
e.printStackTrace(); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
} |