runSimctlWithOutput function
Runs xcrun simctl and returns (stdout, error).
On success, error is null and stdout contains the process output.
On failure, stdout is null and error contains the error message.
Implementation
Future<({String? stdout, String? error})> runSimctlWithOutput(List<String> args) async {
try {
final result = await Process.run('xcrun', ['simctl', ...args]);
if (result.exitCode != 0) {
final err = (result.stderr as String).trim();
return (stdout: null, error: err.isNotEmpty ? err : 'simctl exited with code ${result.exitCode}');
}
return (stdout: (result.stdout as String), error: null);
} catch (e) {
return (stdout: null, error: 'Failed to run xcrun simctl: $e');
}
}