[ACCEPTED]-How do I access argv / command line options in Dart?-dart
Accepted answer
Using Options is no longer an option, use:
void main(List<String> args) {
print(args);
}
To 3 get executable, use Platform.executable 2 (Platform comes from dart:io)
For parsing 1 arguments passed to main, use this cool package
Edit: This is no longer valid, see accepted 1 answer above.
See Options
.
http://api.dartlang.org/dart_io/Options.html
List<String> argv = (new Options()).arguments;
// dart 1.0
import 'dart:io';
void main(List<String> args) {
String exec = Platform.executable;
List<String> flags = Platform.executableArguments;
Uri script = Platform.script;
print("exec=$exec");
print("flags=$flags");
print("script=$script");
print("script arguments:");
for(String arg in args)
print(arg);
}
0
#!/usr/bin/env dart
main() {
print("Args: " + new Options().arguments);
}
0
I use this library for defining and parsing 1 command line args http://pub.dartlang.org/packages/args
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.