run function

Future<List<ProcessResult>> run(
  1. String script, {
  2. bool throwOnError = true,
  3. String? workingDirectory,
  4. Map<String, String>? environment,
  5. bool includeParentEnvironment = true,
  6. bool? runInShell,
  7. Encoding stdoutEncoding = systemEncoding,
  8. Encoding stderrEncoding = systemEncoding,
  9. Stream<List<int>>? stdin,
  10. StreamSink<List<int>>? stdout,
  11. StreamSink<List<int>>? stderr,
  12. bool verbose = true,
  13. bool? commandVerbose,
  14. bool? commentVerbose,
  15. void onProcess(
    1. Process process
    )?,
})

Run one or multiple plain text command(s).

Commands can be split by line.

Commands can be on multiple line if ending with ^ or \.

Returns a list of executed command line results. Verbose by default.

await run('flutter build');
await run('dart --version');
await run('''
 dart --version
 git status
''');

Implementation

Future<List<ProcessResult>> run(
  String script, {
  bool throwOnError = true,
  String? workingDirectory,
  Map<String, String>? environment,
  bool includeParentEnvironment = true,
  bool? runInShell,
  Encoding stdoutEncoding = systemEncoding,
  Encoding stderrEncoding = systemEncoding,
  Stream<List<int>>? stdin,
  StreamSink<List<int>>? stdout,
  StreamSink<List<int>>? stderr,
  bool verbose = true,

  // Default to true
  bool? commandVerbose,
  // Default to true if verbose is true
  bool? commentVerbose,
  void Function(Process process)? onProcess,
}) {
  return Shell(
          throwOnError: throwOnError,
          workingDirectory: workingDirectory,
          environment: environment,
          includeParentEnvironment: includeParentEnvironment,
          runInShell: runInShell,
          stdoutEncoding: stdoutEncoding,
          stderrEncoding: stderrEncoding,
          stdin: stdin,
          stdout: stdout,
          stderr: stderr,
          verbose: verbose,
          commandVerbose: commandVerbose,
          commentVerbose: commentVerbose)
      .run(script, onProcess: onProcess);
}