Apr-22-2020, 02:05 AM
I'm using python 2.7.5 I currently using subprocess to run a local command and I'm trying to iterate over a list to get the status of each device.
example partial command "status" output: there are about 50 items in the output
name: one
date: blah
status: ok
name: two
date: blah
status: bad
partial code:
import subprocess, os
status = subprocess.Popen('command', 'option1', 'option2', var, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = status.communicate()
expected output:
one ok
two bad
etc
attempts:
I tried using a for line in output statement with multiple if statements for if 'name' and if 'status' while appending them to a list, but i'm not sure if this is the best way. Any thoughts?
example partial command "status" output: there are about 50 items in the output
name: one
date: blah
status: ok
name: two
date: blah
status: bad
partial code:
import subprocess, os
status = subprocess.Popen('command', 'option1', 'option2', var, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = status.communicate()
expected output:
one ok
two bad
etc
attempts:
I tried using a for line in output statement with multiple if statements for if 'name' and if 'status' while appending them to a list, but i'm not sure if this is the best way. Any thoughts?