1 package org.peterd.util.process;
2
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 import org.peterd.util.io.StreamCopier;
8
9 public class QuickProcess {
10 protected String[] cmdLine;
11 protected IEnvironmentSetup envSetup;
12 protected String output;
13 protected int result;
14
15 public QuickProcess (String[] cmdLine) {
16 this(cmdLine, null);
17 }
18
19 public QuickProcess (String[] cmdLine, IEnvironmentSetup envSetup) {
20 this.cmdLine = cmdLine;
21 this.envSetup = envSetup;
22 output = null;
23 }
24
25 protected String[] tweakCmdLine(String[] orig) {
26 return orig;
27 }
28
29 public synchronized void exec() throws IOException {
30 ProcessBuilder b = new ProcessBuilder(tweakCmdLine(cmdLine));
31 if (envSetup != null) {
32 envSetup.setupEnvironment(b.environment());
33 }
34 b.redirectErrorStream(true);
35 java.lang.Process p = b.start();
36 ByteArrayOutputStream out = new ByteArrayOutputStream();
37 try {
38 p.getOutputStream().close();
39 InputStream in = p.getInputStream();
40 StreamCopier.fullCopy(in,out);
41 in.close();
42 } catch (IOException e) {
43 //ignore?
44 }
45 output = out.toString();
46 try {
|
Event guarded_by_access: |
Field "org.peterd.util.process.QuickProcess.result" guarded by lock "org.peterd.util.process.QuickProcess.this". |
| Also see events: |
[unguarded_access][lock_event] |
47 result = p.waitFor();
48 } catch (InterruptedException e) {
49 throw new RuntimeException("Unexpected thread interruption");
50 }
51 }
52
53 public String[] getCmdLine() {
54 return cmdLine;
55 }
56
57 public String getOutput() {
58 if (output == null) throw new IllegalStateException();
59 return output;
60 }
61
62 public int getResult() {
63 if (output == null) throw new IllegalStateException();
|
Event unguarded_access: |
Accessing "org.peterd.util.process.QuickProcess.result" without holding a lock on "org.peterd.util.process.QuickProcess.this". |
| Also see events: |
[lock_event][guarded_by_access] |
64 return result;
65 }
66 }