@@ -26,11 +26,11 @@ public class AsyncProcessHandle implements IIOClosable {
26
26
27
27
public AsyncProcessHandle (ThreadContext tc , SixModelObject queue , SixModelObject argsObj ,
28
28
String cwd , SixModelObject envObj , SixModelObject configObj ) {
29
- List <String > args = getArgs (tc , argsObj );
30
- Map <String , String > env = getEnv (tc , envObj );
31
- Map <String , SixModelObject > config = getConfig (tc , configObj );
29
+ final List <String > args = getArgs (tc , argsObj );
30
+ final Map <String , String > env = getEnv (tc , envObj );
31
+ final Map <String , SixModelObject > config = getConfig (tc , configObj );
32
32
33
- ProcessBuilder pb = new ProcessBuilder (args );
33
+ final ProcessBuilder pb = new ProcessBuilder (args );
34
34
pb .directory (new File (cwd ));
35
35
pb .environment ().clear ();
36
36
pb .environment ().putAll (env );
@@ -39,27 +39,39 @@ public AsyncProcessHandle(ThreadContext tc, SixModelObject queue, SixModelObject
39
39
this .queue = queue ;
40
40
this .tc = tc ;
41
41
this .hllConfig = tc .curFrame .codeRef .staticInfo .compUnit .hllConfig ;
42
- try {
43
- this .proc = pb .start ();
44
- SixModelObject ready = config .get ("ready" );
45
- if (ready != null )
46
- send (ready );
47
- }
48
- catch (Throwable t ) {
49
- SixModelObject message = boxError (t .getMessage ());
50
-
51
- SixModelObject error = config .get ("error" );
52
- if (error != null )
53
- send (error , message );
54
-
55
- SixModelObject stdoutBytes = config .get ("stdout_bytes" );
56
- if (stdoutBytes != null )
57
- send (stdoutBytes , this .hllConfig .intBoxType , this .hllConfig .strBoxType , message );
58
-
59
- SixModelObject stderrBytes = config .get ("stderr_bytes" );
60
- if (stderrBytes != null )
61
- send (stderrBytes , this .hllConfig .intBoxType , this .hllConfig .strBoxType , message );
62
- }
42
+ new Thread (new Runnable () {
43
+ public void run () {
44
+ try {
45
+ AsyncProcessHandle .this .proc = pb .start ();
46
+
47
+ SixModelObject ready = config .get ("ready" );
48
+ if (ready != null )
49
+ send (ready );
50
+
51
+ int outcome = AsyncProcessHandle .this .proc .waitFor ();
52
+ SixModelObject done = config .get ("done" );
53
+ if (done != null )
54
+ send (done , boxInt (outcome ));
55
+ }
56
+ catch (Throwable t ) {
57
+ SixModelObject message = boxError (t .getMessage ());
58
+
59
+ SixModelObject error = config .get ("error" );
60
+ if (error != null )
61
+ send (error , message );
62
+
63
+ SixModelObject stdoutBytes = config .get ("stdout_bytes" );
64
+ if (stdoutBytes != null )
65
+ send (stdoutBytes , AsyncProcessHandle .this .hllConfig .intBoxType ,
66
+ AsyncProcessHandle .this .hllConfig .strBoxType , message );
67
+
68
+ SixModelObject stderrBytes = config .get ("stderr_bytes" );
69
+ if (stderrBytes != null )
70
+ send (stderrBytes , AsyncProcessHandle .this .hllConfig .intBoxType ,
71
+ AsyncProcessHandle .this .hllConfig .strBoxType , message );
72
+ }
73
+ }
74
+ }).start ();
63
75
}
64
76
65
77
private List <String > getArgs (ThreadContext tc , SixModelObject argsObj ) {
@@ -112,6 +124,10 @@ private SixModelObject boxError(String error) {
112
124
return Ops .box_s (error , this .hllConfig .strBoxType , this .tc );
113
125
}
114
126
127
+ private SixModelObject boxInt (int value ) {
128
+ return Ops .box_i (value , this .hllConfig .intBoxType , this .tc );
129
+ }
130
+
115
131
public void writeBytes (ThreadContext tc , AsyncTaskInstance task , SixModelObject toWrite ) {
116
132
}
117
133
0 commit comments