How to get (or set) environment variable in Dart, which is accessible for String.fromEnvironment()? I'm doing the following:
import "dart:io";
main() {
Map<String, String> env = Platform.environment;
print(env["NUMBER_OF_PROCESSORS"]); // prints 12
var s = new String.fromEnvironment("NUMBER_OF_PROCESSORS", defaultValue: "No");
print(s); // prints No
}
Is this a bug, or I'm doing anything wrong? If environment variables from Platform.environment
are not seen for String.fromEnvironment()
then how to get (or set) environment variables which will work with String.fromEnvironment()
?
I'm using Windows 7 and Dart VM version: 1.21.0-dev.11.3 (Mon Dec 05 02:56:25 2016) on "windows_x64"
See #27585
new String.fromEnvironment("NUMBER_OF_PROCESSORS", defaultValue: "No")
will retrieve the parameter provided by dart -DNUMBER_OF_PROCESSORS=2314 myProg.dart
with String.fromEnvironment() you can query variables passed to a dart program.
e.g pub build --define PRODUCTION=true
in code ...
var production=String.fromEnvironment("PRODUCTION")
Thank you! Now it's clean
Most helpful comment
See #27585
new String.fromEnvironment("NUMBER_OF_PROCESSORS", defaultValue: "No")
will retrieve the parameter provided bydart -DNUMBER_OF_PROCESSORS=2314 myProg.dart