File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
app/src/processing/app/tools Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ package processing .app .tools ;
2
+
3
+ import org .apache .commons .exec .DefaultExecutor ;
4
+ import org .apache .commons .exec .ExecuteStreamHandler ;
5
+
6
+ import java .io .IOException ;
7
+ import java .io .InputStream ;
8
+ import java .io .OutputStream ;
9
+
10
+ /**
11
+ * Handy process executor, collecting stdout into a given OutputStream
12
+ */
13
+ public class ExternalProcessExecutor extends DefaultExecutor {
14
+
15
+ public ExternalProcessExecutor (final OutputStream os ) {
16
+ this .setStreamHandler (new ExecuteStreamHandler () {
17
+ @ Override
18
+ public void setProcessInputStream (OutputStream outputStream ) throws IOException {
19
+ }
20
+
21
+ @ Override
22
+ public void setProcessErrorStream (InputStream inputStream ) throws IOException {
23
+ }
24
+
25
+ @ Override
26
+ public void setProcessOutputStream (InputStream inputStream ) throws IOException {
27
+ byte [] buf = new byte [4096 ];
28
+ int bytes = -1 ;
29
+ while ((bytes = inputStream .read (buf )) != -1 ) {
30
+ os .write (buf , 0 , bytes );
31
+ }
32
+ }
33
+
34
+ @ Override
35
+ public void start () throws IOException {
36
+ }
37
+
38
+ @ Override
39
+ public void stop () {
40
+ }
41
+ });
42
+
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments