1 | {↵ | | 1 | {↵
|
2 | p = Runtime.getRuntime().exec(command);↵ | | 2 | this.p = Runtime.getRuntime().exec(command);↵
|
|
3 | errorStream = new StreamThread(p.getErrorStream());↵ | | 3 | errorStream = new StreamThread(p.getErrorStream());↵
|
4 | outputStream = new StreamThread(p.getInputStream());↵ | | 4 | outputStream = new StreamThread(p.getInputStream());↵
|
5 | inputStream = p.getOutputStream();↵ | | 5 | inputStream = p.getOutputStream();↵
|
|
6 | errorStream.start();↵ | | 6 | errorStream.start();↵
|
7 | outputStream.start();↵ | | 7 | outputStream.start();↵
|
8 | }↵ | | 8 | }↵
|
|
9 | public void send(String in) throws Exception {↵ | | 9 | public void send(String in) throws Exception {↵
|
10 | inputStream.write(in.getBytes());↵ | | 10 | inputStream.write(in.getBytes());↵
|
11 | inputStream.flush();↵ | | 11 | inputStream.flush();↵
|
12 | inputStream.close();↵ | | 12 | inputStream.close();↵
|
13 | }↵ | | 13 | }↵
|
|
14 | public void send(InputStream in) throws Exception {↵ | | 14 | public void send(InputStream in) throws Exception {↵
|
15 | StreamUtils.streamCopy(in, inputStream);↵ | | 15 | StreamUtils.streamCopy(in, inputStream);↵
|
16 | inputStream.flush();↵ | | 16 | inputStream.flush();↵
|
17 | inputStream.close();↵ | | 17 | inputStream.close();↵
|
18 | }↵ | | 18 | }↵
|
|
19 | public int waitFor() throws Exception {↵ | | 19 | public int waitFor() throws Exception {↵
|
20 | int exitVal = p.waitFor();↵ | | 20 | int exitVal = p.waitFor();↵
|
|
21 | return exitVal;↵ | | 21 | return exitVal;↵
|
22 | }↵ | | 22 | }↵
|
|
23 | /**↵ | | 23 | /**↵
|
24 | *↵ | | 24 | ↵
|
| | | 25 | * ↵
|
25 | * return error↵ | | 26 | * return error↵
|
26 | *↵ | | 27 | ↵
|
| | | 28 | * ↵
|
27 | * @return @throws↵ | | 29 | * @return↵
|
28 | * Exception↵ | | 30 | * @throws Exception↵
|
29 | */↵ | | 31 | */↵
|
30 | public String getErrorString() throws Exception {↵ | | 32 | public String getErrorString() throws Exception {↵
|
31 | String str = errorStream.getBuffer();↵ | | 33 | String str = errorStream.getBuffer();↵
|
|
32 | return str;↵ | | 34 | return str;↵
|
33 | }↵ | | 35 | }↵
|
|
34 | /**↵ | | 36 | /**↵
|
35 | *↵ | | 37 | *↵
|
| | | 38 | ↵
|
36 | * return output↵ | | 39 | * return output↵
|
37 | *↵ | | 40 | *↵
|
| | | 41 | ↵
|
38 | * @return @throws↵ | | 42 | * @return↵
|
39 | * ↵ | | |
|
40 | Exception↵ | | 43 | * @throws Exception↵
|
41 | */↵ | | 44 | */↵
|
42 | public String getOutputString() throws Exception {↵ | | 45 | public String getOutputString() throws Exception {↵
|
43 | String str = outputStream.getBuffer();↵ | | 46 | String str = outputStream.getBuffer();↵
|
|
44 | return str;↵ | | 47 | return str;↵
|
45 | }↵ | | 48 | }↵
|
|
46 | /*↵ | | 49 | /*↵
|
47 | * wait for stream threads to die↵ | | 50 | * wait for stream threads to die↵
|
48 | *↵ | | 51 | ↵
|
| | | 52 | * ↵
|
49 | */↵ | | 53 | */↵
|
50 | public void waitForThreads() throws Exception {↵ | | 54 | public void waitForThreads() throws Exception {↵
|
51 | outputStream.join();↵ | | 55 | outputStream.join();↵
|
52 | errorStream.join();↵ | | 56 | errorStream.join();↵
|
53 | | | 57 |
|