use std::{
env, io,
path::PathBuf,
process::{self, Command},
};
fn inner_main() -> io::Result<PathBuf> {
let exe = env::current_exe()?;
let dir = exe.parent().expect("Executable must be in some directory");
let dir = dir.join("nvs");
Ok(dir)
}
fn main() {
let path = inner_main().expect("Couldn't get path.");
let path = path.into_os_string().into_string().unwrap();
Command::new("cd")
.arg(&path)
.status()
.expect("Something went wrong.");
process::exit(0);
}
I grab the path that the binary is in, go into the parent directory so the binaries name is no longer in the path and then append "nvs" at the end of the path and then in main()
I put the inner_main()
function in a let and then redeclare the let as a string so I can cd into the directory.
Whenever it tries CDing into the nvs directory nothing happens and I know that the command runs because if I move the binary somewhere with no nvs file in it's same directory it runs saying it can't find that directory so my question is when it's in a directory with nvs why doesn't it actually cd into the said directory like it should?