L LuckyTaxi Diamond Member Dec 24, 2000 6,044 23 81 Dec 3, 2008 #1 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')
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,364 4,068 75 Dec 3, 2008 #2 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()
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 Dec 3, 2008 #3 (in_file, out_file) = os.popen2("my_command") myList = out_file.readlines() Edit: I hate python...
D Dravic Senior member May 18, 2000 892 0 76 Dec 4, 2008 #4 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') Click to expand... cmd = "dpkg --list | grep mysql" for mydata in os.popen(cmd).readlines(): print mydata.rstrip() print should obviously be indented
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') Click to expand... cmd = "dpkg --list | grep mysql" for mydata in os.popen(cmd).readlines(): print mydata.rstrip() print should obviously be indented