Nicolas François
Nicolas François

Reputation: 777

Access to user environment variable

In my .bashrc file:

export DART_SDK=/home/nicolas/dart/dart-sdk

In command line, it works when I "echo" it. But I cannot see this user variable from dart with, I just see system variable but not mine:

var env = Platform.environment;
env.forEach((k,v) => print("Key=$k Value=$v"));

I tried:

Is my user variable is not well defined? Is my code is bad? It's a bug?

Upvotes: 17

Views: 9700

Answers (1)

Cutch
Cutch

Reputation: 3575

Using the following code:

import 'dart:io'; // Server side / command line only package.

main() {
  Map<String, String> env = Platform.environment;
  env.forEach((k, v) => print("Key=$k Value=$v"));
}

I was able to override environment variables on both Windows and Mac. On Mac I had to add the line to .bash_profile (.bashrc is not loaded on my Mac).

John

Here is the link to Platform class docs

Upvotes: 25

Related Questions