#open #xdg-open #start #launch

bin+lib open

Open a path or URL using the program configured on the system

13 stable releases

1.3.2 Aug 11, 2019
1.3.1 Jul 28, 2019
1.2.2 Aug 5, 2018
1.2.1 Sep 24, 2017
1.0.2 Feb 28, 2015

#1 in #open

Download history 7804/week @ 2019-04-28 7496/week @ 2019-05-05 7365/week @ 2019-05-12 9365/week @ 2019-05-19 11056/week @ 2019-05-26 12391/week @ 2019-06-02 11286/week @ 2019-06-09 12581/week @ 2019-06-16 10679/week @ 2019-06-23 8956/week @ 2019-06-30 6933/week @ 2019-07-07 7287/week @ 2019-07-14 7665/week @ 2019-07-21 8034/week @ 2019-07-28 7276/week @ 2019-08-04

39,769 downloads per month
Used in 69 crates (49 directly)

MIT license

7KB
109 lines

Build Status

Use this library to open a path or URL using the program configured on the system. It is equivalent to running one of the following:

# OSX
$ open <path-or-url>
# Windows
$ start <path-or-url>
# Linux
$ open <path-or-url> || xdg-open <path-or-url> || gnome-open <path-or-url> || kde-open <path-or-url>

Usage

Add this to your Cargo.toml

[dependencies]
open = "*"

Add this to your lib ...

extern crate open;

... and open something using

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

Follow this link for the massive API docs.

Credits

The implementation is based on the respective functionality of cargo, but was improved to allow some error handling.


lib.rs:

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;

# #[test]
# fn doit() {
open::that("http://rust-lang.org").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.

# fn doit() {
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),
}
# }

Dependencies

~537KB