std::osOperating system interfaces.
Access command-line arguments, environment variables, and system information.
import std.os;
fn main() {
let arguments = os.args();
match arguments.get(0) {
.Some(first) => println(first),
.None => println("no program argument"),
}
let home = os.home_dir();
println(home);
}
argsReturn all command-line arguments, including the program name.
import std.os;
fn main() {
let arguments = os.args();
match arguments.get(0) {
.Some(program) => println(program),
.None => println("no program argument"),
}
}
envGet the value of an environment variable.
Returns None if the variable is not set.
import std.os;
fn main() {
let path = os.env("PATH");
}
set_envSet an environment variable for the current process.
Environment names must be non-empty and cannot contain =.
remove_envRemove an environment variable.
Environment names must be non-empty and cannot contain =.
has_envCheck whether an environment variable is set.
cwdReturns the current working directory.
home_dirReturns the user's home directory.
hostnameReturns the system hostname.
pidReturns the current process ID.
temp_dirReturns the system temporary directory path.
Uses the platform-appropriate temp directory (e.g. /tmp on Unix,
%TEMP% on Windows). Trailing separators are stripped.
import std.os;
fn main() {
let tmp = os.temp_dir();
let path = tmp + "/myfile.txt";
}
EnvErrorInvalid environment-variable name.
InvalidName(string)