So, I'm on windows 10 and I've been trying to code an app which will read a config on $HOME/.myapp
I have a vague recollection of using this before and with no issues but now env::var
doesn't look like it can read HOME from powershell and cmd however it works fine on MINGW64 or wsl terminal.
I've written a very simple app using the env::var
example from their docs:
#![allow(unused)]
fn main() {
use std::env;
let key = "HOME";
match env::var(key) {
Ok(val) => println!("{}: {:?}", key, val),
Err(e) => println!("couldn't interpret {}: {}", key, e),
}
}
If I run it on MINGW64 or WSL terminal it returns the content of the variable HOME.
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target\debug\test-env.exe`
Content of HOME env variable: C:\Users\my.user
WSL returns /home/user
However, if I try on powershell or cmd I get this error
PS C:\source\__github\rust\test-env> cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running `target\debug\test-env.exe`
couldn't interpret HOME: environment variable not found
If in powershell for example I just type $HOME
it prints the value of HOME.
PS C:\source\__github\rust\test-env> $HOME
C:\Users\my.user
This is my rustup --version:
rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.54.0 (a178d0322 2021-07-26)`
Am I missing something?