runCommand function

Future<List<ProcessResult>> runCommand(
  1. String workingDirectory,
  2. String command, {
  3. bool verbose = true,
  4. bool ignoreError = false,
  5. StreamSink<List<int>>? stdout,
})

Implementation

Future<List<ProcessResult>> runCommand(
  String workingDirectory,
  String command, {
  bool verbose = true,
  bool ignoreError = false,
  StreamSink<List<int>>? stdout,
}) async {
  logger.log('执行命令:[$workingDirectory] [$command]');
  final shell = Shell(
    workingDirectory: workingDirectory,
    verbose: verbose,
    stdout: stdout,
  );
  final results = await shell.run(command);
  final errorTexts =
      results.map((e) => e.errText).where((element) => element.isNotEmpty);
  if (results.any((element) => element.exitCode != 0) && !ignoreError) {
    logger.log(errorTexts.join('\n'), status: LogStatus.error);
    exit(2);
  }
  logger.log('执行命令: $command 完成', status: LogStatus.success);
  return results;
}