os.system('cd foo')
runs /bin/sh -c "cd foo"
This does work: It launches a new shell, changes that shell's current working directory into foo
, and then allows that shell to exit when it reaches the end of the script it was called with.
However, if you want to change the directory of your current process, as opposed to the copy of /bin/sh
that system()
creates, you need that call to be run within that same process; hence, os.chdir()
.