Python Forum
Best way to iterate through output to get the status of devices
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to iterate through output to get the status of devices
#1
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?
Reply


Messages In This Thread
Best way to iterate through output to get the status of devices - by idkwhatimdoing - Apr-22-2020, 02:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make the script ignore down devices. wagnergt12 4 3,261 Apr-20-2020, 11:45 PM
Last Post: wagnergt12
  Where is usually located the python interpreter on android devices? anddontyoucomebacknomore 1 2,280 Jul-03-2019, 06:32 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020