ben-albrecht
ben-albrecht

Reputation: 1865

How to read an environment variable from a Chapel program?

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

Upvotes: 3

Views: 79

Answers (1)

ben-albrecht
ben-albrecht

Reputation: 1865

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.

Upvotes: 3

Related Questions