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

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

AEI2 0.99u:

  • Added duration output for executed commands
  • Added total time output for both applying patches and combine binaries tasks of installation
File size: 1.7 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.Date;
9import java.util.List;
10import java.util.Vector;
11
12/**
13 * @author Christian Illy
14 */
15public class AppExecution {
16 /**
17 * Execute a short running application and wait for termination
18 *
19 * @param cmdLine
20 * List of command and arguments
21 * @return Error code and list of output lines
22 * @throws IOException
23 * Exc
24 */
25 public static AppExecutionResult executeAndWait(Vector<String> cmdLine)
26 throws IOException {
27 long start = new Date().getTime();
28 ProcessBuilder pb = new ProcessBuilder(cmdLine);
29 pb.redirectErrorStream(true);
30 Process proc = pb.start();
31
32 InputStream is = proc.getInputStream();
33 InputStreamReader isr = new InputStreamReader(is);
34 BufferedReader br = new BufferedReader(isr);
35
36 String line;
37 Vector<String> lines = new Vector<String>();
38
39 while ((line = br.readLine()) != null) {
40 lines.add(line);
41 }
42 try {
43 proc.waitFor();
44 } catch (InterruptedException e) {
45 // TODO Auto-generated catch block
46 e.printStackTrace();
47 }
48 return new AppExecutionResult(proc.exitValue(), cmdLine, lines,
49 (int) (new Date().getTime() - start));
50 }
51
52 /**
53 * Execute an app without waiting
54 *
55 * @param cmd
56 * Command and parameters
57 * @param workingDirectory
58 * Working directory of app
59 */
60 public static void execute(List<String> cmd, File workingDirectory) {
61 try {
62 ProcessBuilder pb = new ProcessBuilder(cmd);
63 pb.directory(workingDirectory);
64 pb.start();
65 } catch (IOException e) {
66 e.printStackTrace();
67 }
68 }
69
70}
Note: See TracBrowser for help on using the repository browser.