i'm working on a project, and running into a little problem. It's designed to be a simple shell, and right now, I'm working on entering the built in commands (pwd, cd, exit). I've got all but CD working.
The parsing works, and the different segments of the command and arguments are put into an array, so right now I have this:
void cd()
{
chdir(commands[1].c_str());
reset();
}
I run that, with a valid path that is in that directory, but it doesn't change. What am I missing?
Thanks!
You comment:
Can tell directory doesn't change because immediately after, when I run a PWD, (
getenv("PWD")
), it still shows the original directory that the program was launched in.
You're checking the current working directory incorrectly. See chdir() not affecting environment variable PWD
Instead of using getenv("PWD")
use getcwd
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments