runSync function

List<ProcessResult> runSync(
  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. StreamSink<List<int>>? stdout,
  10. StreamSink<List<int>>? stderr,
  11. bool verbose = true,
  12. bool? commandVerbose,
  13. bool? commentVerbose,
  14. ShellOptions? options,
})

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.

runSync('flutter build');
runSync('dart --version');
runSync('''
 dart --version
 git status
''');

Compared to the async version, it is not possible to kill the spawn process nor to feed any input.

Implementation

List<ProcessResult> runSync(
  String script, {
  bool throwOnError = true,
  String? workingDirectory,
  Map<String, String>? environment,
  bool includeParentEnvironment = true,
  bool? runInShell,
  Encoding stdoutEncoding = systemEncoding,
  Encoding stderrEncoding = systemEncoding,
  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,

  /// Override all other options parameters
  ShellOptions? options,
}) {
  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,
          options: options)
      .runSync(script);
}