How do I access argv / command line options in Dart?

这一生的挚爱 提交于 2019-12-01 07:03:09
Tomas Kulich

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

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;
igor
// 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);
}
mcandre
#!/usr/bin/env dart

main() {
    print("Args: " + new Options().arguments);
}

I use this library for defining and parsing command line args http://pub.dartlang.org/packages/args

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!