executeCommand method

Future<String> executeCommand(
  1. String command,
  2. List<String> args, {
  3. String? workingDirectory,
  4. String? errorMessage,
  5. String? processMessage,
})

Implementation

Future<String> executeCommand(String command, List<String> args,
    {String? workingDirectory,
    String? errorMessage,
    String? processMessage}) async {
  final process =
      logger.progress(processMessage ?? "$command ${args.join(" ")}");
  final result =
      await Process.run(command, args, workingDirectory: workingDirectory);
  process.finish();
  if (result.exitCode != 0) {
    throw ProcessExecutionException(
        errorMessage ?? "Error executing $command: ${result.stderr}".trim());
  }
  return result.stdout.toString().trim();
}