2
2
3
3
import backtype .storm .task .TopologyContext ;
4
4
import java .io .BufferedReader ;
5
+ import java .io .InputStream ;
5
6
import java .io .InputStreamReader ;
6
7
import java .io .DataOutputStream ;
7
8
import java .io .File ;
8
9
import java .io .IOException ;
9
10
import java .util .Map ;
10
11
import java .util .List ;
12
+
13
+ import org .apache .commons .io .IOUtils ;
11
14
import org .json .simple .JSONObject ;
12
15
import org .json .simple .JSONValue ;
13
16
14
17
public class ShellProcess {
15
18
private DataOutputStream processIn ;
16
19
private BufferedReader processOut ;
20
+ private InputStream processErrorStream ;
17
21
private Process _subprocess ;
18
22
private String [] command ;
19
23
@@ -28,6 +32,7 @@ public Number launch(Map conf, TopologyContext context) throws IOException {
28
32
29
33
processIn = new DataOutputStream (_subprocess .getOutputStream ());
30
34
processOut = new BufferedReader (new InputStreamReader (_subprocess .getInputStream ()));
35
+ processErrorStream = _subprocess .getErrorStream ();
31
36
32
37
JSONObject setupInfo = new JSONObject ();
33
38
setupInfo .put ("pidDir" , context .getPIDDir ());
@@ -69,8 +74,19 @@ private String readString() throws IOException {
69
74
//synchronized (processOut) {
70
75
while (true ) {
71
76
String subline = processOut .readLine ();
72
- if (subline ==null )
73
- throw new RuntimeException ("Pipe to subprocess seems to be broken! Currently read output: " + line .toString ());
77
+ if (subline ==null ) {
78
+ StringBuilder errorMessage = new StringBuilder ();
79
+ errorMessage .append ("Pipe to subprocess seems to be broken!" );
80
+ if (line .length () == 0 ) {
81
+ errorMessage .append (" No output read.\n " );
82
+ }
83
+ else {
84
+ errorMessage .append (" Currently read output: " + line .toString () + "\n " );
85
+ }
86
+ errorMessage .append ("Shell Process Exception:\n " );
87
+ errorMessage .append (IOUtils .toString (processErrorStream ) + "\n " );
88
+ throw new RuntimeException (errorMessage .toString ());
89
+ }
74
90
if (subline .equals ("end" )) {
75
91
break ;
76
92
}
0 commit comments