run function
Synchronously run an executable
.
If quiet
is false, logs the stdout. The stderr is always logged.
Returns the stdout.
All other optional parameters are forwarded to Process.runSync.
Implementation
String run(String executable,
{List<String> arguments = const [],
RunOptions? runOptions,
bool quiet = false,
String? workingDirectory}) {
runOptions = mergeWorkingDirectory(workingDirectory, runOptions);
if (!quiet) log("$executable ${arguments.join(' ')}");
final result = Process.runSync(executable, arguments,
workingDirectory: runOptions.workingDirectory,
environment: runOptions.environment,
includeParentEnvironment: runOptions.includeParentEnvironment,
runInShell: runOptions.runInShell,
stdoutEncoding: runOptions.stdoutEncoding,
stderrEncoding: runOptions.stderrEncoding);
var stdout = result.stdout as String;
var stderr = result.stderr as String;
if (!quiet && stdout.isNotEmpty) log(stdout.trim());
if (stderr.isNotEmpty) log(result.stderr);
if (result.exitCode != 0) {
throw ProcessException._(executable, result.exitCode, stdout, stderr);
}
return stdout;
}