capturing output of command line in an array
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Wed Oct 31 23:23:49 EDT 2007
En Wed, 31 Oct 2007 19:20:56 -0300, <amjadcsu at gmail.com> escribió:
> I am looking to just get the node name from that info.
> I dont need all other info
> so my list would be just
> alist=[node13,node12,node8,node1 ....]
> is it possible??
>
>> > node13 2 ( 0/ 56) [ 0.00, 0.00, 0.00] [ 0.0, 0.0,
>> > 0.1, 99.9, 0.0] OFF
>> > node12 2 ( 1/ 63) [ 0.99, 0.97, 0.91] [ 46.6, 0.0,
>> > 3.7, 49.8, 0.0] OFF
>> > node8 2 ( 1/ 59) [ 0.99, 0.97, 0.91] [ 47.5, 0.0,
>> > 2.8, 49.7, 0.0] OFF
Try this:
import subprocess
p = subprocess.Popen( ["your","command","+args"], stdout=subprocess.PIPE)
lines = p.stdout.readlines()
p.wait()
If you are only interested in the first word in each line, you may replace
the lines = ... above with this:
nodes = [line.split(' ', 1)[0] for line in p.stdout]
--
Gabriel Genellina
More information about the Python-list
mailing list