I understand that i am supposed to use chdir() but I just need an explanation as to why calling cd shell command through system or execvp() from a child process would not work? Thanks!!
Asked
Active
Viewed 2,388 times
1 Answers
5
Because chdir
only modifies the environment of the current process. It can't touch the environment of the parent.
See also the link posted by tripleee.

cnicutar
- 178,505
- 25
- 365
- 392
-
1This is a way too frequent FAQ. http://www.faqs.org/faqs/unix-faq/faq/part2/section-8.html – tripleee Aug 19 '11 at 10:50
-
im a beginner in c, please explain.. Your answer answers why I have to use chdir or..? but why can i not use cd through exec() or system().. Thanks – pnizzle Aug 19 '11 at 10:56
-
My answer explains why you **can't** change the directory. `cd` relies on `chdir`. – cnicutar Aug 19 '11 at 10:57
-
Thanks, im not the (for as long as i've got it working) person; i try understand what im doing. Thanks again !! – pnizzle Aug 19 '11 at 11:14