Module os

Operating system interfaces.

Access command-line arguments, environment variables, and system information.

Examples

import std::os;

fn main() {
    let n = os.args_count();
    let first = os.args(0);
    let home = os.home_dir();
    println(home);
}

Contents

Functions

Function args_count

pub fn args_count() -> i32

Returns the number of command-line arguments.

Function args

pub fn args(index: i32) -> string

Returns the command-line argument at the given index.

Index 0 is the program name. Panics if index is out of range.

Examples

let program = os.args(0);
let first_arg = os.args(1);

Function env

pub fn env(name: string) -> string

Get the value of an environment variable.

Returns an empty string if the variable is not set.

Examples

let path = os.env("PATH");

Function set_env

pub fn set_env(name: string, value: string)

Set an environment variable for the current process.

Function remove_env

pub fn remove_env(name: string)

Remove an environment variable.

Function has_env

pub fn has_env(name: string) -> bool

Check whether an environment variable is set.

Function cwd

pub fn cwd() -> string

Returns the current working directory.

Function home_dir

pub fn home_dir() -> string

Returns the user's home directory.

Function hostname

pub fn hostname() -> string

Returns the system hostname.

Function pid

pub fn pid() -> i32

Returns the current process ID.