I'm trying to replicate the cd
command in Rust, just for learning.
But the problem is that I'm not sure how to change a directory in the OS (*nix). I have tried with:
std::process::Command::new("cd")
.arg(path) //path is a String
.spawn()
.expect("Directory failed");
And also tried with:
let path = Path::new(path_str.as_str());
let changed_dir = env::set_current_dir(&path).is_ok();
And changed_dir
is true.
Even I tried changing env::set_var("PWD", path)
but nothing seems to work.
I checked this part of the documentation: https://doc.rust-lang.org/std/env/fn.set_current_dir.html but I think is just for a type of sandboxed path or directory.
Any more ideas?