I am trying to use output of external program run using the run function.
this program regularly throws a row of data which i need to use in mine script
I have found a subprocess library and used its run()
/check_output()
Example:
def usual_process():
# some code here
for i in subprocess.check_output(['foo','$$']):
some_function(i)
Now assuming that foo is already in a PATH variable and it outputs a string in semi-random periods.
I want the program to do its own things, and run some_function(i)
every time foo sends new row to its output.
which boiles to two problems. piping the output into a for loop and running this as a background subprocess Thank you
Update: I have managed to get the foo output onto some_function using This
with os.popen('foo') as foos_output:
for line in foos_output:
some_function(line)
According to this os.popen is to be deprecated, but I am yet to figure out how to pipe internal processes in python Now just need to figure out how to run this function in a background
I am trying to limit distro-specific code to minimum and stick to Pyton3 if possible. The resulting code will be mostly targeting Raspbian at first but in a latter version android. Intention is prity much to be updating the variable based on _foo_'s output, while the program does other things – Tomas Apr 09 '17 at 02:51