I dont know if its the best way to do this but it will work.
You can read in everything your program prints into the console by typing this:
Here we print print("test-test-test-test")
into the console, like opencv
does it, and with p.stdout.readline()
you can read it in again.
import os
import sys
from subprocess import Popen, PIPE, STDOUT
script_path = os.path.join('name_of_your_program.py')
p = Popen([sys.executable, '-u', script_path],
stdout=PIPE, stderr=STDOUT, bufsize=1)
while True:
print("test-test-test-test")
string = p.stdout.readline()
print(string[0:3])
Output:
test-test-test-test
b'tes'
test-test-test-test
b"b'T"
test-test-test-test
b'tes'
(It reads in binary so you have to convert it to a string.)