Please help me find out if this is possible. Follow me here with this explanation.
The important thing is, I do not want to invoke/run/launch a python program, from within another python program. I want to interact with a program that is already running independently.
First, pretend this application is already running, constantly spitting output to the console, one second at a time, forever.
#RunningProgram.py
from time import sleep
counter = 0
while True:
print('Counter increment: ' + str(counter))
counter += 1
sleep(1)
I would like to have another application that can somehow hook into this while it is running, and get info from the console output. THIS IS PSEUDO CODE
#Sniffer.py
def Sniff_Output(process_name):
if process_name.isActive():
last_line = process_name.output.lastline()
print(last_line)
Sniff_Output(RunningProgram)
#ideally this would just read from what RunningProgram.py
#is doing, and then print that out to the console in Sniffer.py
I have been reading topics on SO here but it looks like all the subprocessing modules refer to running other programs, and being a host. I would like to just key-in to something that is already running independently.