Python Forum
How to caputre an output of a CLI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to caputre an output of a CLI
#3
You can capture and store the output in a variable by pointing sys.stdout to the variable and executing your command.
eg->
o_variable = StringIO()      # variable to store stdout stream
sys.stdout = o_variable      # pointing stdout to variable
#Execute your commands
sys.stdout = sys.__stdout__  #restore std out
output = o_variable.getvalue()
print(output)
Reply


Messages In This Thread
How to caputre an output of a CLI - by vel9194 - Aug-07-2017, 09:07 AM
RE: How to caputre an output of a CLI - by hbknjr - Aug-07-2017, 02:17 PM

Forum Jump:

User Panel Messages

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