runProcess function

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

Implementation

Future<ProcessResult> runProcess(
  String executable,
  List<String> arguments, {
  String? workingDirectory,
  Map<String, String>? environment,
  bool includeParentEnvironment = true,
  bool runInShell = false,
  Encoding? stdoutEncoding = systemEncoding,
  Encoding? stderrEncoding = systemEncoding,
  bool printCall = false,
}) async {
  _runProcessLogger.log(printCall ? Level.INFO : Level.FINE,
      '$executable ${arguments.join(' ')}');
  final result = await Process.run(
    executable,
    arguments,
    workingDirectory: workingDirectory,
    environment: environment,
    includeParentEnvironment: includeParentEnvironment,
    runInShell: runInShell,
    stdoutEncoding: stdoutEncoding,
    stderrEncoding: stderrEncoding,
  );

  final stdOut = result.stdout;
  if (stdOut is String && stdOut.isNotEmpty) _runProcessLogger.finer(stdOut);

  final stdErr = result.stderr;
  if (stdErr is String && stdErr.isNotEmpty) _runProcessLogger.severe(stdErr);

  if (result.exitCode != 0) throw Exception(result.stderr.toString());
  return result;
}