Mercurial > projects > dbus-d
comparison dbus-d-javahelper/jsrc/dbus_d_javahelper/ConsoleProcess.java @ 0:a5576806d36d
recreate repository without any libs for lightweight repository
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 20 Oct 2007 18:07:18 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a5576806d36d |
---|---|
1 /* | |
2 * License: Public Domain | |
3 * written by Frank Benoit | |
4 */ | |
5 package dbus_d_javahelper; | |
6 | |
7 import java.io.BufferedReader; | |
8 import java.io.File; | |
9 import java.io.IOException; | |
10 import java.io.InputStream; | |
11 import java.io.InputStreamReader; | |
12 import java.io.OutputStream; | |
13 import java.io.OutputStreamWriter; | |
14 import java.io.PrintWriter; | |
15 | |
16 public class ConsoleProcess { | |
17 | |
18 private final Thread threadStdout; | |
19 private final Thread threadStderr; | |
20 private final Process process; | |
21 | |
22 private class StreamPump extends Thread { | |
23 | |
24 private final InputStream istr; | |
25 private final OutputStream ostr; | |
26 | |
27 public StreamPump(InputStream istr, OutputStream ostr) { | |
28 this.istr = istr; | |
29 this.ostr = ostr; | |
30 } | |
31 | |
32 public void run() { | |
33 BufferedReader inputStream = new BufferedReader( | |
34 new InputStreamReader(istr)); | |
35 PrintWriter writer = new PrintWriter(new OutputStreamWriter(ostr)); | |
36 String c; | |
37 try { | |
38 while ((c = inputStream.readLine()) != null) { | |
39 writer.println(c); | |
40 writer.flush(); | |
41 } | |
42 } catch (IOException e) { | |
43 e.printStackTrace(); | |
44 } | |
45 } | |
46 } | |
47 public ConsoleProcess( String[] cmdarray, String[] envp, File basedir, OutputStream stdout, OutputStream stderr ) throws IOException{ | |
48 process = Runtime.getRuntime().exec( cmdarray, envp, basedir ); | |
49 threadStdout = new StreamPump( process.getInputStream(), stdout ); | |
50 threadStderr = new StreamPump( process.getErrorStream(), stderr ); | |
51 | |
52 threadStdout.start(); | |
53 threadStderr.start(); | |
54 } | |
55 | |
56 public int join() throws InterruptedException{ | |
57 process.waitFor(); | |
58 threadStdout.join(); | |
59 threadStderr.join(); | |
60 return process.exitValue(); | |
61 } | |
62 | |
63 public void interrupt() { | |
64 process.destroy(); | |
65 } | |
66 } |