How to run commands in command line from a script

Ivan Shevanski darkpaladin79 at
Fri Jul 1 05:43:00 CEST 2005

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')            '


>From: Robert Kern <rkern at>
>To: python-list at
>Subject: Re: How to run commands in command line from a script
>Date: Thu, 30 Jun 2005 20:01:29 -0700
>Ivan Shevanski wrote:
> > I know there is an easy way to do this, and I just can not remember. I 
> > already searched where I thought the module would be. . . I just want to 
> > some name specific commands.  Is this easily possible?
>Quick and dirty:
>    import os
>    os.system('./some --command')
>More robust: Use the subprocess module.
>Robert Kern
>rkern at
>"In the fields of hell where the grass grows high
>   Are the graves of dreams allowed to die."
>    -- Richard Harter

Don’t just search. Find. Check out the new MSN Search!

More information about the Python-list mailing list