I use Windows 11, and I need to perform the following tasks:
- Navigate to a specific directory called
dir
. - Execute a program named
program
located in that directory. - Return to the original path.
In terminal I can achieve this by typing:
cd dir; execute program; cd ..
So, I attempted to use Python’s os.system
module as follows:
os.system('cd dir; run program; cd ..')
However, for some reason, this approach does not seem to work.
I also tried to use os.chdir
but it did not solve my problem.
New contributor
Lory Hendrix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.