Populate a list in Python

LuckyTaxi

Diamond Member
Dec 24, 2000
6,044
23
81
How can I populate a list w/ the output of the command that ran?

#!/usr/bin/python

import os
os.system('dpkg --list | grep mysql')
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,250
3,845
75
Good question. It looks like it's almost, but not quite, as simple as Perl:

import subprocess
IN = subprocess.Popen('dpkg --list | grep mysql',shell=True,stdout=subprocess.PIPE)
yourList = IN.communicate()[0].splitlines()
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
(in_file, out_file) = os.popen2("my_command")
myList = out_file.readlines()

Edit: I hate python...
 

Dravic

Senior member
May 18, 2000
892
0
76
Originally posted by: LuckyTaxi
How can I populate a list w/ the output of the command that ran?

#!/usr/bin/python

import os
os.system('dpkg --list | grep mysql')




cmd = "dpkg --list | grep mysql"

for mydata in os.popen(cmd).readlines():
print mydata.rstrip()





print should obviously be indented