source: AE/installer2/src/net/oni2/aeinstaller/backend/appexecution/AppExecution.java@ 702

Last change on this file since 702 was 702, checked in by alloc, 12 years ago

AEI2 0.99u:

  • Fixed a few bugs in apply patches
  • Added some log output to apply patches
File size: 1.6 KB
Line 
1package net.oni2.aeinstaller.backend.appexecution;
2
3import java.io.BufferedReader;
4import java.io.File;
5import java.io.IOException;
6import java.io.InputStream;
7import java.io.InputStreamReader;
8import java.util.List;
9import java.util.Vector;
10
11/**
12 * @author Christian Illy
13 */
14public class AppExecution {
15 /**
16 * Execute a short running application and wait for termination
17 *
18 * @param cmdLine
19 * List of command and arguments
20 * @return Error code and list of output lines
21 * @throws IOException
22 * Exc
23 */
24 public static AppExecutionResult executeAndWait(Vector<String> cmdLine)
25 throws IOException {
26 ProcessBuilder pb = new ProcessBuilder(cmdLine);
27 pb.redirectErrorStream(true);
28 Process proc = pb.start();
29
30 InputStream is = proc.getInputStream();
31 InputStreamReader isr = new InputStreamReader(is);
32 BufferedReader br = new BufferedReader(isr);
33
34 String line;
35 Vector<String> lines = new Vector<String>();
36
37 while ((line = br.readLine()) != null) {
38 lines.add(line);
39 }
40 try {
41 proc.waitFor();
42 } catch (InterruptedException e) {
43 // TODO Auto-generated catch block
44 e.printStackTrace();
45 }
46 return new AppExecutionResult(proc.exitValue(), cmdLine, lines);
47 }
48
49 /**
50 * Execute an app without waiting
51 *
52 * @param cmd
53 * Command and parameters
54 * @param workingDirectory
55 * Working directory of app
56 */
57 public static void execute(List<String> cmd, File workingDirectory) {
58 try {
59 ProcessBuilder pb = new ProcessBuilder(cmd);
60 pb.directory(workingDirectory);
61 pb.start();
62 } catch (IOException e) {
63 e.printStackTrace();
64 }
65 }
66
67}
Note: See TracBrowser for help on using the repository browser.