问题
And does Dart have a getopt library?
回答1:
Using Options is no longer an option, use:
void main(List<String> args) {
print(args);
}
To get executable, use Platform.executable (Platform comes from dart:io)
For parsing arguments passed to main, use this cool package
回答2:
Edit: This is no longer valid, see accepted answer above.
See Options
.
http://api.dartlang.org/dart_io/Options.html
List<String> argv = (new Options()).arguments;
回答3:
// 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);
}
回答4:
#!/usr/bin/env dart
main() {
print("Args: " + new Options().arguments);
}
回答5:
I use this library for defining and parsing command line args http://pub.dartlang.org/packages/args
来源:https://stackoverflow.com/questions/9279541/how-do-i-access-argv-command-line-options-in-dart