Crate open[][src]

Use this library to open a path or URL using the program configured on the system.

Usage

The following should open the given URL in a web browser

extern crate open;

open::that("http://rust-lang.org").unwrap();

Alternatively, specify the program to open something with. It should expect to receive the path or URL as first argument.

extern crate open;

open::with("http://rust-lang.org", "firefox").unwrap();

Notes

As an operating system program is used, chances are that the open operation fails. Therefore, you are advised to at least check the result with .is_err() and behave accordingly, e.g. by letting the user know what you tried to open, and failed.

match open::that("http://rust-lang.org") {
    Ok(exit_status) => {
        if exit_status.success() {
            println!("Look at your browser!");
        } else {
            if let Some(code) = exit_status.code() {
                println!("Command returned non-zero exit status {}!", code);
            } else {
                println!("Command returned with unknown exit status!");
            }
        }
    }
    Err(why) => println!("Failure to execute command: {}", why),
}

Functions

that
that_in_background

Convenience function for opening the passed path in a new thread. See documentation of that(...) for more details.

with
with_in_background