I have this bit of code
Code:
} else if (strcmp(command->cmdArgs[0], "cd") == 0) {
if (!command->cmdArgs[1]) {
// no directory was given
sprintf(dir, "%s", getenv("HOME"));
} else if (strncmp(command->cmdArgs[1], "/", 1) == 0) {
sprintf(dir, "%s", command->cmdArgs[1]);
} else {
// relative path
sprintf(dir, "%s/%s", getenv("PWD"), command->cmdArgs[1]);
}
if (chdir(dir) == -1) {
printf("no such file or directory\n");
fflush(stdout);
status = 1;
// exit(EXIT_FAILURE);
}
Let's say I'm in the current directory (e.g /some/test/dir) and I have these files/folders: test1.txt, testDir, and so on
If I pass in "cd testDir" then I am able to cd into the testDir folder with chdir().
But if I do "cd" first to go to HOME, then do mkdir testDir2, then do "cd testDir2" it doesn't work. Perror gives back no such file or directory
I'm executing these commands with execvp().