run method

  1. @override
Future<ProcessResult> run(
  1. String script, {
  2. Map<String, String>? environment,
  3. Stream<List<int>>? stdin,
  4. StreamSink<List<int>>? stdout,
  5. List<String>? args,
})
override

Runs a command within a IShell environment. Returning the commands result. May throw CommandExceptions.

since 0.0.1

Implementation

@override
Future<ProcessResult> run(
  String script, {
  Map<String, String>? environment,
  Stream<List<int>>? stdin,
  StreamSink<List<int>>? stdout,
  List<String>? args,
}) async {
  _requireSingleCommand(script);
  var cmd = buildCmdWithArgs(script, args);
  _log.fine('Running: $cmd');
  ProcessResult res;
  try {
    var result = await _prRun(
      cmd,
      verbose: _verbose,
      environment: environment ?? _environment,
      workingDirectory: _workingDirectory,
      stdout: stdout,
      stdin: stdin,
    );
    res = result.first;
  } on pr.ShellException catch (ex) {
    if (!_throwOnError && ex.result != null) {
      res = ex.result!;
    } else {
      throw ChassisShellException(ex.message, ex.result, cmd);
    }
  }
  return ProcessResult(
    res.pid,
    res.exitCode,
    tryTrimRight(res.stdout),
    tryTrimRight(res.stderr),
  );
}