@@ -173,7 +173,7 @@ Future<Process> startProcess(
173
173
String workingDirectory,
174
174
}) async {
175
175
final String command = '$executable ${arguments ?.join (" " ) ?? "" }' ;
176
- print ('Executing : $command ' );
176
+ print ('\n Executing : $command ' );
177
177
environment ?? = < String , String > {};
178
178
environment['BOT' ] = 'true' ;
179
179
final Process process = await _processManager.start (
@@ -184,8 +184,8 @@ Future<Process> startProcess(
184
184
final ProcessInfo processInfo = new ProcessInfo (command, process);
185
185
_runningProcesses.add (processInfo);
186
186
187
- process.exitCode.whenComplete (( ) {
188
- print ('\n ' ); // separate the output of this script from subsequent output to make logs easier to read
187
+ process.exitCode.then (( int exitCode ) {
188
+ print ('exitcode: $ exitCode ' );
189
189
_runningProcesses.remove (processInfo);
190
190
});
191
191
@@ -218,15 +218,22 @@ Future<int> exec(
218
218
}) async {
219
219
final Process process = await startProcess (executable, arguments, environment: environment);
220
220
221
+ final Completer <Null > stdoutDone = new Completer <Null >();
222
+ final Completer <Null > stderrDone = new Completer <Null >();
221
223
process.stdout
222
224
.transform (UTF8 .decoder)
223
225
.transform (const LineSplitter ())
224
- .listen (print);
226
+ .listen ((String line) {
227
+ print ('stdout: $line ' );
228
+ }, onDone: () { stdoutDone.complete (); });
225
229
process.stderr
226
230
.transform (UTF8 .decoder)
227
231
.transform (const LineSplitter ())
228
- .listen (stderr.writeln);
232
+ .listen ((String line) {
233
+ print ('stderr: $line ' );
234
+ }, onDone: () { stderrDone.complete (); });
229
235
236
+ await Future .wait <Null >(< Future <Null >> [stdoutDone.future, stderrDone.future]);
230
237
final int exitCode = await process.exitCode;
231
238
232
239
if (exitCode != 0 && ! canFail)
@@ -237,24 +244,39 @@ Future<int> exec(
237
244
238
245
/// Executes a command and returns its standard output as a String.
239
246
///
240
- /// Standard error is redirected to the current process' standard error stream .
247
+ /// For logging purposes, the command's output is also printed out .
241
248
Future <String > eval (
242
249
String executable,
243
250
List <String > arguments, {
244
251
Map <String , String > environment,
245
252
bool canFail: false ,
246
253
}) async {
247
254
final Process process = await startProcess (executable, arguments, environment: environment);
248
- process.stderr.listen ((List <int > data) {
249
- stderr.add (data);
250
- });
251
- final String output = await UTF8 .decodeStream (process.stdout);
255
+
256
+ final StringBuffer output = new StringBuffer ();
257
+ final Completer <Null > stdoutDone = new Completer <Null >();
258
+ final Completer <Null > stderrDone = new Completer <Null >();
259
+ process.stdout
260
+ .transform (UTF8 .decoder)
261
+ .transform (const LineSplitter ())
262
+ .listen ((String line) {
263
+ print ('stdout: $line ' );
264
+ output.writeln (line);
265
+ }, onDone: () { stdoutDone.complete (); });
266
+ process.stderr
267
+ .transform (UTF8 .decoder)
268
+ .transform (const LineSplitter ())
269
+ .listen ((String line) {
270
+ print ('stderr: $line ' );
271
+ }, onDone: () { stderrDone.complete (); });
272
+
273
+ await Future .wait <Null >(< Future <Null >> [stdoutDone.future, stderrDone.future]);
252
274
final int exitCode = await process.exitCode;
253
275
254
276
if (exitCode != 0 && ! canFail)
255
277
fail ('Executable failed with exit code $exitCode .' );
256
278
257
- return output.trimRight ();
279
+ return output.toString (). trimRight ();
258
280
}
259
281
260
282
Future <int > flutter (String command, {
0 commit comments