Shell Executor
A cross-platform utility for executing shell commands in Dart/Flutter apps.
π§ Features
- Supports Windows (
powershell
/cmd.exe
) - Supports macOS/Linux (
zsh
,bash
,sh
) - Gracefully rejects execution on Android/iOS with a clear message
- Executes multiple commands sequentially with
&&
chaining - Returns trimmed standard output or detailed error messages
- Simple static method API for quick integration
π Usage
import 'package:flutter_shell/flutter_shell.dart';
void main() async {
final result = await ShellExecutor.executeCommands([
'echo Hello',
'echo World',
]);
print(result);
}
π§© API Reference
ShellExecutor.executeCommands
static Future<String> executeCommands(List<String> commands)
-
Executes the provided list of shell commands sequentially in a platform-appropriate shell.
-
Returns a
Future<String>
which is:- The trimmed standard output (
stdout
) on success. - An error message string prefixed with β on failure.
- A platform-specific unsupported message on mobile platforms.
- The trimmed standard output (
π οΈ Installation
Add the package to your pubspec.yaml
:
dependencies:
flutter_shell: ^0.0.1
Then run:
flutter pub get
π Example
Example CLI usage in bin/main.dart
:
import 'package:flutter_shell/flutter_shell.dart';
Future<void> main() async {
print('π Running ShellExecutor from terminal...\n');
final result = await ShellExecutor.executeCommands([
'echo Hello',
'echo from flutter_shell!',
]);
print('π§ Command output:\n$result');
}
β οΈ Supported Platforms
- Windows, macOS, Linux
- Not supported: Android and iOS (returns an error message)
π° Support
If you find this project helpful, consider sponsoring me on GitHub π
π€ Contributing
Contributions and suggestions are welcome! Feel free to open issues or submit pull requests.
π License
MIT License Β© 2025 Your Name