Python Forum
How to excess external program and get a value back?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to excess external program and get a value back?
#2
Use check_output.
It will return output as a whole bytes object so can decode(to string) and split at '/r/n' to get lines.
Example untested:
from subprocess import check_output

command = check_output(["gphoto2", "--get-config", "/main/capturesettings/shutterspeed"])
output = command.decode().strip()
sspeed = output.split('\r\n')[2]

with open('sspeed.txt') as f_out:
    f_out.write(sspeed)
Reply


Messages In This Thread
RE: How to excess external program and get a value back? - by snippsat - Jun-11-2018, 11:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't read data from the clipboard in an external program AlekseyPython 1 2,718 Mar-19-2019, 07:56 AM
Last Post: buran
  How can I move in an external program via Python? Pythoner 0 2,344 Dec-29-2018, 12:43 PM
Last Post: Pythoner
  Embedding Args in external program call brizflysdrones 5 5,041 May-09-2017, 08:29 PM
Last Post: buran
  input-external program-output baolevani 2 4,039 Mar-27-2017, 04:34 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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