fbf331e0dd
Change-Id: I42b4a44fd6a2197e499e8623274b3cd1a4b5556f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394003 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
47 lines
1.0 KiB
Dart
47 lines
1.0 KiB
Dart
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
Future<int> runProcess(
|
|
String command,
|
|
List<String> args, {
|
|
String? cwd,
|
|
bool failOnError = true,
|
|
bool verbose = true,
|
|
List<String>? stdout,
|
|
}) async {
|
|
if (verbose) {
|
|
print('\n$command ${args.join(' ')}');
|
|
}
|
|
|
|
var process = await Process.start(command, args, workingDirectory: cwd);
|
|
|
|
process.stdout.transform(utf8.decoder).transform(LineSplitter()).listen((
|
|
line,
|
|
) {
|
|
if (verbose) {
|
|
print(' $line');
|
|
}
|
|
if (stdout != null) {
|
|
stdout.add(line);
|
|
}
|
|
});
|
|
process.stderr.transform(utf8.decoder).transform(LineSplitter()).listen((
|
|
line,
|
|
) {
|
|
if (verbose) {
|
|
print(' $line');
|
|
}
|
|
});
|
|
|
|
var exitCode = await process.exitCode;
|
|
if (exitCode != 0 && failOnError) {
|
|
throw '$command exited with $exitCode';
|
|
}
|
|
|
|
return exitCode;
|
|
}
|