@@ -117,7 +117,13 @@ public static Operation Execute(string cmd,Options options = null){
117
117
start . RedirectStandardInput = true ;
118
118
start . StandardOutputEncoding = options . encoding ;
119
119
start . StandardErrorEncoding = options . encoding ;
120
+
121
+ if ( operation . isKillRequested ) {
122
+ return ;
123
+ }
124
+
120
125
p = Process . Start ( start ) ;
126
+ operation . BindProcess ( p ) ;
121
127
122
128
p . ErrorDataReceived += delegate ( object sender , DataReceivedEventArgs e ) {
123
129
UnityEngine . Debug . LogError ( e . Data ) ;
@@ -135,12 +141,11 @@ public static Operation Execute(string cmd,Options options = null){
135
141
break ;
136
142
}
137
143
line = line . Replace ( "\\ " , "/" ) ;
138
-
139
144
Enqueue ( delegate ( ) {
140
145
operation . FeedLog ( LogType . Log , line ) ;
141
146
} ) ;
142
-
143
147
} while ( true ) ;
148
+
144
149
while ( true ) {
145
150
string error = p . StandardError . ReadLine ( ) ;
146
151
if ( string . IsNullOrEmpty ( error ) ) {
@@ -179,6 +184,15 @@ public class Options{
179
184
public class Operation {
180
185
public event UnityAction < LogType , string > onLog ;
181
186
public event UnityAction < int > onExit ;
187
+
188
+ private Process _process ;
189
+
190
+ private bool _killRequested = false ;
191
+
192
+ internal void BindProcess ( Process process ) {
193
+ _process = process ;
194
+ }
195
+
182
196
internal void FeedLog ( LogType logType , string log ) {
183
197
if ( onLog != null ) {
184
198
onLog ( logType , log ) ;
@@ -187,6 +201,26 @@ internal void FeedLog(LogType logType,string log){
187
201
this . hasError = true ;
188
202
}
189
203
}
204
+
205
+ public bool isKillRequested {
206
+ get {
207
+ return _killRequested ;
208
+ }
209
+ }
210
+
211
+ public void Kill ( ) {
212
+ if ( _killRequested ) {
213
+ return ;
214
+ }
215
+ _killRequested = true ;
216
+ if ( _process != null ) {
217
+ _process . Kill ( ) ;
218
+ _process = null ;
219
+ } else {
220
+ FireDone ( 137 ) ;
221
+ }
222
+ }
223
+
190
224
public bool hasError {
191
225
get ; private set ;
192
226
}
0 commit comments