executeCommandWithOutput method

Future<String?> executeCommandWithOutput(
  1. String command, [
  2. String? player
])

Execute a command and get the output

Implementation

Future<String?> executeCommandWithOutput(
  String command, [
  String? player,
]) async {
  try {
    final args = player != null ? ['--player=$player', command] : [command];
    final result = await Process.run('playerctl', args, runInShell: true);

    if (result.exitCode == 0) {
      return result.stdout.toString().trim();
    }
    return null;
  } catch (e) {
    debugPrint('Error executing command $command: $e');
    return null;
  }
}