[Tutor] Dos command

Bill Mill bill.mill at gmail.com
Thu Aug 12 13:09:31 CEST 2004


Ali,

Note that I'm on linux, so I'll use linux commands, but you can
substitute them easily for dos ones. You can definitely do it with the
os module,

>>> import os
>>> st_in, st_out = os.popen2('mount')
>>> st_out.readlines()
['/dev/hda5 on / type ext3 (rw)\n',
 'none on /proc type proc (rw)\n',
 'none on /sys type sysfs (rw)\n',
 'none on /dev/pts type devpts (rw,gid=5,mode=620)\n',
 'usbdevfs on /proc/bus/usb type usbdevfs (rw)\n',
 'none on /dev/shm type tmpfs (rw)\n',
 '/dev/hda7 on /home type ext3 (rw)\n',
 '/dev/hda2 on /c type vfat (rw,uid=500,gid=500)\n',
 '/dev/hda3 on /music type vfat (rw,uid=500,gid=500,umask=000)\n',
 'sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)\n',
 'none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)\n']

You can also do it with the commands module:

>>> import commands
>>> commands.getoutput('mount').split('\n')
['/dev/hda5 on / type ext3 (rw)',
 'none on /proc type proc (rw)',
 'none on /sys type sysfs (rw)',
 'none on /dev/pts type devpts (rw,gid=5,mode=620)',
 'usbdevfs on /proc/bus/usb type usbdevfs (rw)',
 'none on /dev/shm type tmpfs (rw)',
 '/dev/hda7 on /home type ext3 (rw)',
 '/dev/hda2 on /c type vfat (rw,uid=500,gid=500)',
 '/dev/hda3 on /music type vfat (rw,uid=500,gid=500,umask=000)',
 'sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)',
 'none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)']

this might be clearer if you're only reading, not writing, data.

Peace
Bill Mill



----- Original Message -----
From: Ali Polatel <alipolatel at yahoo.com>
Date: Thu, 12 Aug 2004 02:56:33 -0700 (PDT)
Subject: [Tutor] Dos command
To: tutor at python.org

Dear Friends,
I want to put the result of a dos-command in a list..how can i do
this?(I remember it was related with os module but forgot the
function)
for example dir command...
Regards

 ________________________________
Do you Yahoo!?
 Yahoo! Mail - 50x more storage than other providers!


More information about the Tutor mailing list