1

I'm able to use popen to run just about any program, but apparently not cd:

#include <stdio.h>
void main() {
    FILE *fp = popen("cd", "w");
    pclose(fp);
}

I'd expect that to change directory to home but nothing happens. Changing to "r", or changing to e.g. "cd ~", "cd /", does not help. Using system has about the same result, i.e. works for anything but cd. So how is it done? The answers here don't work for me. Thank you.

Erik Vesterlund
  • 481
  • 6
  • 19

1 Answers1

0

cd is generally a shell internal command, NOT an executable.

Even if it were, in general no process can change another process's working directory, so it would change the cwd for the "cd" process and then upon exit it'd be gone.

Dale
  • 534
  • 4
  • 13