[ACCEPTED]-How do I access argv / command line options in Dart?-dart

Accepted answer
Score: 29

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

Score: 4

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;
Score: 4
// 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

Score: 1
#!/usr/bin/env dart

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

0

Score: 1

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

More Related questions