Is it possible to pass command-line arguments to a new isolate from spawnUri()


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

main() {
  var options = new Options();
  print(options.arguments);    // prints ["Hello World"]

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).


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.

Answered By – Justin Fagnani

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *