15

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:

  • on windows and it works
  • on mac but doesn't work

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

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567

1 Answers1

22

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 dart docs: https://api.dartlang.org/1.13.0/dart-io/Platform-class.html

Soul_man
  • 575
  • 5
  • 15
Cutch
  • 3,511
  • 1
  • 18
  • 12
  • Thanks, so my code is good. After some tests, the behaviour is strange : when I run from Dart Editor, I cannot see my user variable(linux and Mac OS), but I run it with command line it works ... – Nicolas François Sep 28 '12 at 18:15
  • Hi Nicolas, this is likely because Dart Editor is not running inside a bash shell but spawned from the Dock or Finder which has it's own set of environment variables. See this post for how to control environment variables for launched application- http://stackoverflow.com/questions/603785/environment-variables-in-mac-os-x – Cutch Sep 28 '12 at 20:58