Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

current_exe return \\\?\\ prefix symbols #99931

Closed
bmiyuan opened this issue Jul 30, 2022 · 5 comments
Closed

current_exe return \\\?\\ prefix symbols #99931

bmiyuan opened this issue Jul 30, 2022 · 5 comments
Labels
O-windows Operating system: Windows

Comments

@bmiyuan
Copy link

bmiyuan commented Jul 30, 2022

Background:
I use current_exe() on Windows, but std::env::current_exe() return "\\?\D:\code\test\target\debug\test.exe"

Steps to Reproduce:
fn main() {
let program_dir=std::env::current_exe().unwrap();
println!("program_dir {:?}",&program_dir);
}

Rust Version:
rustc 1.62.1 (e092d0b 2022-07-16)

Expected Behavior:
I would expect to get:
"D:\code\test\target\debug\test.exe"

Actual Behavior:
"\\?\D:\code\test\target\debug\test.exe"

@bjorn3
Copy link
Member

bjorn3 commented Jul 30, 2022

libstd uses GetModuleFileNameW to get the executable name:

|buf, sz| unsafe { c::GetModuleFileNameW(ptr::null_mut(), buf, sz) },
This function seems to indeed return \\?\ prefixed paths. libstd can handle these paths just fine, and they are mandatory when the path gets too long. Not a windows expert, but I did say not a bug.

@bjorn3 bjorn3 added the O-windows Operating system: Windows label Jul 30, 2022
@the8472
Copy link
Member

the8472 commented Jul 30, 2022

These are valid paths. If you need to pass them to an application which can't handle them you can try using the dunce crate, but it's not guaranteed that this will work for all paths because verbatim paths can refer to files that are unnamable by non-verbatim ones. Not only due to lengths but also due to some parsing that happens.

@mati865
Copy link
Contributor

mati865 commented Jul 31, 2022

There is also unstable absolute function.

@nagisa
Copy link
Member

nagisa commented Aug 1, 2022

Largely a…

Duplicate of #59117

@nagisa nagisa marked this as a duplicate of #59117 Aug 1, 2022
@nagisa nagisa closed this as completed Aug 1, 2022
@Zoxc
Copy link
Contributor

Zoxc commented Mar 25, 2023

#59117 seems to be a separate issue about turning paths absolute.

olexiyb added a commit to Sanctum-AI/tauri that referenced this issue Jun 19, 2024
due to rust feature on windows rust-lang/rust#99931 use dunce::canonicalize() to get proper name
olexiyb added a commit to Sanctum-AI/tauri that referenced this issue Jun 19, 2024
due to rust feature on windows rust-lang/rust#99931 use dunce::canonicalize() to get proper name
olexiyb added a commit to Sanctum-AI/tauri that referenced this issue Jul 22, 2024
due to rust feature on windows rust-lang/rust#99931 use dunce::canonicalize() to get proper name
olexiyb added a commit to Sanctum-AI/tauri that referenced this issue Aug 4, 2024
due to rust feature on windows rust-lang/rust#99931 use dunce::canonicalize() to get proper name
olexiyb added a commit to Sanctum-AI/tauri that referenced this issue Aug 12, 2024
due to rust feature on windows rust-lang/rust#99931 use dunce::canonicalize() to get proper name
olexiyb added a commit to Sanctum-AI/tauri that referenced this issue Aug 19, 2024
due to rust feature on windows rust-lang/rust#99931 use dunce::canonicalize() to get proper name
olexiyb added a commit to Sanctum-AI/tauri that referenced this issue Aug 26, 2024
due to rust feature on windows rust-lang/rust#99931 use dunce::canonicalize() to get proper name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

6 participants