std::env::current_exe - Rust
Description: API documentation for the Rust `current_exe` fn in crate `std`.
Keywords: rust, rustlang, rust-lang, current_exe

# 1.0.0[−][src]Function std::env::current_exe

    pub fn current_exe() -> Result<PathBuf>

Returns the full filesystem path of the current running executable.

# Platform-specific behavior

If the executable was invoked through a symbolic link, some platforms will return the path of the symbolic link and other platforms will return the path of the symbolic link’s target.

# Errors

Acquiring the path of the current executable is a platform-specific operation that can fail for a good number of reasons. Some errors can include, but not be limited to, filesystem operations failing or general syscall failures.

# Security

The output of this function should not be used in anything that might have security implications. For example:

    fn main() {
        println!("{:?}", std::env::current_exe());
    }Run

On Linux systems, if this is compiled as `foo`:

    $ rustc foo.rs
    $ ./foo
    Ok("/home/alex/foo")

And you make a hard link of the program:

    $ ln foo bar

When you run it, you won’t get the path of the original executable, you’ll get the path of the hard link:

    $ ./bar
    Ok("/home/alex/bar")

This sort of behavior has been known to lead to privilege escalation when used incorrectly.

# Examples

    use std::env;

    match env::current_exe() {
        Ok(exe_path) => println!("Path of this executable is: {}",
                                 exe_path.display()),
        Err(e) => println!("failed to get current exe path: {}", e),
    };Run

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)