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.