pnizzle
pnizzle

Reputation: 6431

why calling cd shell command through system() or execvp() from a child process won't work?

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!!

Upvotes: 2

Views: 2459

Answers (1)

cnicutar
cnicutar

Reputation: 182724

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.

Upvotes: 5

Related Questions