How to get the os.system data into a variable

Emile van Sebille emile at fenx.com
Tue Dec 19 20:30:22 EST 2000


import os
info = os.popen('ls -l').readlines()

HTH

Emile van Sebille
emile at fenx.com


jicman wrote:

> Hi all!
> 
> I know that
> 
> t = os.system('ls -l')
> 
> return code and assigns it to t.  I would like to get the data, not the code, 
> that is resulted from the command into a variable.  (i.e.
> 
> -rw-r--r--   1 root     other        821 Dec  2 12:20 MyLog.txt
> drwxr-xr-x   2 root     root         512 Dec 21  1999 TT_DB
> drwxrwxrwx   3 root     root         512 Aug 18 17:05 apps
> lrwxrwxrwx   1 root     root           9 Dec 20  1999 bin -> ./usr/bin
> drwxr-xr-x   3 root     nobody       512 Nov 28 12:31 cdrom
> drwxr-xr-x   2 root     other        512 Nov 21 20:10 cgi-bin
> -rw-------   1 root     root      975040 Oct  3 11:34 core
> 
> etc.)
> 
> I know that I could do
> 
> t = os.system('ls -l > mytemp.txt')
> 
> and then read the file, but I would like to acquire that data w/o reading the 
> file.  Oh, and by the way, the command that I am sending is not really ls.  It 
> does not even belong to the unix world.  It's the output of a command from an 
> application that I have.
> 
> Any ideas?  It would be greatly appreciated.
> 
> thanks,
> 
> josé




More information about the Python-list mailing list