How can one read an environment variable within a Chapel program?
Environment variables can be accessed through the C interface by calling getenv
, e.g.
// Compiled and run on Chapel 1.22.0
extern proc getenv(name : c_string) : c_string;
var value = getenv('SOME_ENV_VAR'.c_str()):string;
Anyone may try, test & extend this code online.
For more environment variable APIs, see the user-developed EnvVariables module.