I am new to python and I am trying to write a simple program that would cd from my home directory to another directory, run an ls command and then return to my home directory. The OS is Redhead linux 5.4. I am using python 2.4.3.
I tried this first:
import os
os.system("cd /opt/WindRiver")
os.system("ls")
os.system("cd /home/harry")
The cd command did not work as the ls command listed the files in my home directory, not the new directory.
I then try:
import os
os.chdir("/opt/WindRiver")
os.system("ls")
os.chdir("/home/harry")
chdir worked but looks likes it started a new shell and stayed in the new directory. I had to manually enter the exit command to exit the current shell.
Any suggestions on how to make it work?
Thanks,
Harry Yuen