runBash function

Future<ProcessResult> runBash(
  1. String executable,
  2. List<String> arguments, {
  3. String? workingDirectory,
  4. Map<String, String>? environment,
  5. bool includeParentEnvironment = true,
  6. Encoding? stdoutEncoding = systemEncoding,
  7. Encoding? stderrEncoding = systemEncoding,
  8. bool printCall = false,
})

Implementation

Future<ProcessResult> runBash(
  String executable,
  List<String> arguments, {
  String? workingDirectory,
  Map<String, String>? environment,
  bool includeParentEnvironment = true,
  Encoding? stdoutEncoding = systemEncoding,
  Encoding? stderrEncoding = systemEncoding,
  bool printCall = false,
}) async {
  if (printCall) {
    print('$executable ${arguments.join(' ')}');
  }
  final result = await Process.run(
    'bash',
    ['-c', '$executable ${arguments.join(' ')}'],
    workingDirectory: workingDirectory,
    environment: environment,
    includeParentEnvironment: includeParentEnvironment,
    // Needed to work on windows
    runInShell: true,
    stdoutEncoding: stdoutEncoding,
    stderrEncoding: stderrEncoding,
  );
  if (result.exitCode != 0) throw Exception(result.stderr.toString());
  return result;
}