Dart pub global run can't resolve script name

Skip to first unread message

Borut Jegrišnik

Jan 24, 2016, 7:38:18 PM1/24/16
to Dart Server-side and Cloud Development

I have a simple dart project that has one executable in bin folder (test.dart). I have activated it with dart global activate and now I can run it directly with just typing the name of that executable file.

Inside that dart file I would like to know the path of that script. Basically for now I'm just printing something like this:

print('1: ' + Platform.script.toString());
print('2: ' + Platform.script.path);
print('3: ' + Platform.executable);
print('4: ' + Platform.packageRoot);
print('5: ' + Platform.resolvedExecutable);

When I run it directly:


or with pub:

pub global run test

or even with package name:

pub global run test:test

I always get the same result:

1: http://localhost:53783/test.dart
2: /test.dart
3: E:\apps\dart-sdk\bin\dart
5: E:\apps\dart-sdk\bin\dart.exe

The issue here is that I can't get the absolute path for test.dart file.

When I run it like this:

dart /path/to/project/bin/test.dart

I get what I need:

1: file:///E:/projects/dart/test/bin/test.dart
2: /E:/projects/dart/test/bin/test.dart
3: dart
5: E:\apps\dart-sdk\bin\dart.exe

Is there a way how to get absolute path for a script that is currently running, regardless of a way how it was executed?

Günter Zöchbauer

Jan 25, 2016, 2:25:26 AM1/25/16
to Dart Server-side and Cloud Development

Kevin Moore

Jan 25, 2016, 1:42:25 PM1/25/16
to Günter Zöchbauer, Dart Server-side and Cloud Development
I've added an answer to that stack-overflow question that should help

You received this message because you are subscribed to the Google Groups "Dart Server-side and Cloud Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud+un...@dartlang.org.
Visit this group at https://groups.google.com/a/dartlang.org/group/cloud/.

Natalie Weizenbaum

Jan 25, 2016, 3:39:19 PM1/25/16
to Kevin Moore, Günter Zöchbauer, Dart Server-side and Cloud Development
Reply all
Reply to author
0 new messages