runSync$ method

dynamic runSync$(
  1. List<String> command, {
  2. Encoding? encoding,
  3. String? workingDirectory,
  4. Map<String, String>? environment,
  5. bool includeParentEnvironment = true,
  6. bool silent = false,
  7. bool noPrompt = false,
  8. bool returnCode = false,
  9. bool autoQuote = true,
})

Execute command and returns stdout

Implementation

dynamic runSync$(
  List<String> command, {
  dart_convert.Encoding? encoding,
  String? workingDirectory,
  Map<String, String>? environment,
  bool includeParentEnvironment = true,
  bool silent = false,
  bool noPrompt = false,
  bool returnCode = false,
  bool autoQuote = true,
}) {
  String executable = command[0];
  List<String> arguments = command.sublist(1).toList();
  encoding ??= this.encoding;
  if (workingDirectory != null) {
    workingDirectory = std_misc.pathExpand(workingDirectory);
  }
  workingDirectory ??= dart_io.Directory.current.absolute.path;
  if (autoQuote) {
    executable = _quote(executable);
    arguments = arguments.map((x) => _quote(x)).toList();
  }
  String display = std_misc.joinCommandLine([executable, ...arguments]);
  if (useUnixShell) {
    String command = std_misc.joinCommandLine([executable, ...arguments]);
    executable = unixShell;
    arguments = ['-c', command];
  } else {
    executable = _unquote(executable);
    arguments = arguments.map((x) => _unquote(x)).toList();
  }
  if (!noPrompt) {
    //print('[$workingDirectory] \$ $display');
    dart_io.stderr.write('[$workingDirectory] \$ $display\n');
  }
  dart_io.ProcessResult result = dart_io.Process.runSync(
    executable,
    arguments,
    stdoutEncoding: encoding,
    stderrEncoding: encoding,
    workingDirectory: workingDirectory,
    environment: environment,
    includeParentEnvironment: includeParentEnvironment,
    runInShell: !useUnixShell,
  );
  String stdoutString = (result.stdout as String);
  stdoutString = stdoutString.trimRight();
  stdoutString = std_misc.adjustTextNewlines(stdoutString);
  if (!silent) {
    dart_io.stdout.write(stdoutString);
  }
  dart_io.stderr.write(result.stderr as String);
  if (returnCode) {
    return result.exitCode;
  } else {
    return stdoutString;
  }
}