runProcess static method

Future<int> runProcess(
  1. String command
)

Runs a process

Implementation

static Future<int> runProcess(String command) async {
  List<String> commands = command.split(" ");

  final processArguments = commands.getRange(1, commands.length).toList();

  // `ProcessStartMode.inheritStdio` hands the parent's stdin/stdout/stderr
  // file descriptors to the child directly. Previously this code wired the
  // streams up with `stdin.pipe(process.stdin)`, which left the parent's
  // stdin in a "consumed" state after the child exited and broke any
  // subsequent `readLineSync`-based prompt.
  final process = await Process.start(
    commands.first,
    processArguments,
    runInShell: true,
    mode: ProcessStartMode.inheritStdio,
  );

  final exitCode = await process.exitCode;

  if (exitCode != 0) {
    MetroConsole.writeInRed("Error: $exitCode");
  }

  return exitCode;
}