How to run commands in command line from a script

Robert Kern rkern at ucsd.edu
Thu Jun 30 23:52:01 EDT 2005


Ivan Shevanski wrote:
> Alright well I'm quite a noob and when I run a simple command to change 
> the current directory, nothing happens.  I made a little test script to 
> show it:
> 
> import os
> cwd = os.getcwd()
> print cwd
> os.system('cd = C:\Program Files')
> print cwd
> 
> then the result:
> 
> C:\Python24\Python Scripts
> C:\Python24\Python Scripts
> 
> The cd never changed. . .  Can somebody explain this? I think I need to 
> add something simple, i didnt quite  get the example '        
> os.system('./some --command')            '

Read the documentation. os.system() opens up a new shell process. The 
command to change directories happens in that shell process, not 
python's process.

Try another command.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list