How to read an environment variable from a Chapel program?

86 Views Asked by At

How can one read an environment variable within a Chapel program?

1

There are 1 best solutions below

4
On BEST ANSWER

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.