4

When starting a new isolate with spawnUri(), is it possible to pass command line args into that new isolate?

eg: Command line:

dart.exe app.dart "Hello World"

In app.dart

#import("dart:isolate");
main() {
  var options = new Options();
  print(options.arguments);    // prints ["Hello World"]
  spawnUri("other.dart");
}

In other.dart

main() {
  var options = new Options();
  print(options.arguments);   // prints [] when spawned from app.dart.
                              // Is it possible to supply 
                              // Options from another isolate?
}

Although I can pass data into other.dart through its SendPort, the specific use I want is to use another dart app that hasn't been created with a recievePort callback (such as pub.dart, or any other command-line app).

Chris Buckett
  • 13,738
  • 5
  • 39
  • 46
  • The other option to re-use existing dart scripts is to a new process, passing in command line args, but specifically this questions is about spawning new isolates – Chris Buckett Jul 25 '12 at 06:42

2 Answers2

1

Your example doesn't call print(options.arguments); in other.dart using the current stable SDK.

However

spanUri("other.dart");

spawns an Uri. So how about spawnUri("other.dart?param=value#orViaHash"); and try if you can find the param/value pair via

print(options.executable);
print(options.script);
Alex
  • 8,245
  • 8
  • 46
  • 55
  • Although that might work if I had control over other.dart, I was more interested in scenarios where I could use a third-party other.dart without modification. – Chris Buckett Jul 25 '12 at 06:42
1

As far as I can tell the answer is currently no, and it would be hard to simulate via message passing because the options would not be available in main().

I think there are two good feature requests here. One is to be able to pass options on spawn() so that a script can run the same from the root isolate or a spawned isolate.

The other feature, which could be used to implement the first, is a way to pass messages that are handled by libraries before main() is invoked so that objects that main() depends on can be initialized with data from the spawning isolate.

Justin Fagnani
  • 10,483
  • 2
  • 27
  • 37