run static method

Future<bool> run(
  1. String executable,
  2. List<String> arguments, {
  3. required String workingDirectory,
  4. bool silent = false,
})

Runs a command and returns the result. On non-zero exit, logs the error and returns false.

Implementation

static Future<bool> run(
  String executable,
  List<String> arguments, {
  required String workingDirectory,
  bool silent = false,
}) async {
  try {
    final result = await Process.run(
      executable,
      arguments,
      workingDirectory: workingDirectory,
      runInShell: Platform.isWindows,
    );

    if (result.exitCode != 0) {
      if (!silent) {
        Logger.error('$executable ${arguments.join(' ')} failed');
        if (result.stderr.toString().isNotEmpty) {
          Logger.dim(result.stderr.toString().trim());
        }
      }
      return false;
    }
    return true;
  } catch (e) {
    if (!silent) {
      Logger.error('Failed to run $executable: $e');
    }
    return false;
  }
}