runCommand static method

Future<String> runCommand(
  1. String workDir,
  2. String command
)

Implementation

static Future<String> runCommand(String workDir, String command) async {
  ProcessResult processResult;
  if (Platform.isWindows) {
    processResult = await Process.run('cmd', [
      '/c',
      command,
    ], workingDirectory: workDir);
  } else {
    processResult = await Process.run('bash', [
      '-c',
      command,
    ], workingDirectory: workDir);
  }
  if (processResult.exitCode == 0) {
    return processResult.stdout.toString();
  } else {
    throw CommandException(command, processResult.stderr.toString());
  }
}