Home     My Faqts     Contributors     About     Help    

faqts : Computers : Programming : Languages : Python

FAQTs repaired & updated!
Thanks for your patience...
Entry Add Entry Alert - Edit this Entry

Did You Find This Entry Useful?

6 of 11 people (55%) answered Yes
Recently 5 of 10 people (50%) answered Yes

how do I pass arguments (whats the correct syntax) to the os.system command?

Sep 6th, 2002 02:03

Michael Chermside, Jason Welsh


It is quite simple:
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('del delme')
0
This was on Windows, but the usage on a unix variant is exactly the
same. Simply put exactly what you would type at the command prompt into
a string, and pass it to os.system().
Of course, it's worth mentioning that if you want to see the output,
you'll have to use some variant of popen() instead... something like this:
>>> print os.popen('ls -n').read()
total 611295
drwxrwxrwx   1 1        1              0 Sep  3 14:47 Applications
drwxrwxrwx   1 1        1              0 Apr  2  2001 DRIVERS
drwxrwxrwx   1 1        2              0 Sep  3 16:09 Documents
drwxrwxrwx   1 1        1              0 Nov  5  2001 FOUND.000
drwxrwxrwx   1 1        2              0 Jul 16 13:11 NetAccounts
drwxrwxrwx   1 1        1              0 Jul 30 15:44 Program Files
drwxrwxrwx   1 1        1              0 Apr 19 07:41 Reference
drwxrwxrwx   1 1        1              0 Sep  3 14:49 TEMP
drwxrwxrwx   1 1        1              0 Sep  3 15:44 WINNT
drwxrwxrwx   1 1        1              0 Sep  4  2001 bea
-rwxrwxrwa   1 1        1             43 Apr  2  2001 cmdlines.$$$
drwxrwxrwx   1 1        2              0 Feb 19  2002 cygwin
-rwxrwxrwa   1 1        1            608 Feb 14  2002 sh_histo



© 1999-2004 Synop Pty Ltd