Commit 21f57a85 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Wait for stderr in `runCommandAndStreamOutput()` (#9598)

parent 60c5ffc1
...@@ -102,14 +102,13 @@ Future<Process> runCommand(List<String> cmd, { ...@@ -102,14 +102,13 @@ Future<Process> runCommand(List<String> cmd, {
String workingDirectory, String workingDirectory,
bool allowReentrantFlutter: false, bool allowReentrantFlutter: false,
Map<String, String> environment Map<String, String> environment
}) async { }) {
_traceCommand(cmd, workingDirectory: workingDirectory); _traceCommand(cmd, workingDirectory: workingDirectory);
final Process process = await processManager.start( return processManager.start(
cmd, cmd,
workingDirectory: workingDirectory, workingDirectory: workingDirectory,
environment: _environment(allowReentrantFlutter, environment) environment: _environment(allowReentrantFlutter, environment),
); );
return process;
} }
/// This runs the command and streams stdout/stderr from the child process to /// This runs the command and streams stdout/stderr from the child process to
...@@ -129,7 +128,7 @@ Future<int> runCommandAndStreamOutput(List<String> cmd, { ...@@ -129,7 +128,7 @@ Future<int> runCommandAndStreamOutput(List<String> cmd, {
allowReentrantFlutter: allowReentrantFlutter, allowReentrantFlutter: allowReentrantFlutter,
environment: environment environment: environment
); );
final StreamSubscription<String> subscription = process.stdout final StreamSubscription<String> stdoutSubscription = process.stdout
.transform(UTF8.decoder) .transform(UTF8.decoder)
.transform(const LineSplitter()) .transform(const LineSplitter())
.where((String line) => filter == null ? true : filter.hasMatch(line)) .where((String line) => filter == null ? true : filter.hasMatch(line))
...@@ -144,7 +143,7 @@ Future<int> runCommandAndStreamOutput(List<String> cmd, { ...@@ -144,7 +143,7 @@ Future<int> runCommandAndStreamOutput(List<String> cmd, {
printStatus(message); printStatus(message);
} }
}); });
process.stderr final StreamSubscription<String> stderrSubscription = process.stderr
.transform(UTF8.decoder) .transform(UTF8.decoder)
.transform(const LineSplitter()) .transform(const LineSplitter())
.where((String line) => filter == null ? true : filter.hasMatch(line)) .where((String line) => filter == null ? true : filter.hasMatch(line))
...@@ -157,8 +156,12 @@ Future<int> runCommandAndStreamOutput(List<String> cmd, { ...@@ -157,8 +156,12 @@ Future<int> runCommandAndStreamOutput(List<String> cmd, {
// Wait for stdout to be fully processed // Wait for stdout to be fully processed
// because process.exitCode may complete first causing flaky tests. // because process.exitCode may complete first causing flaky tests.
await subscription.asFuture<Null>(); await Future.wait(<Future<Null>>[
subscription.cancel(); stdoutSubscription.asFuture<Null>(),
stderrSubscription.asFuture<Null>(),
]);
stdoutSubscription.cancel();
stderrSubscription.cancel();
return await process.exitCode; return await process.exitCode;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment