0

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.

Daddy
  • 9,045
  • 7
  • 69
  • 98
  • 1
    Or this: https://stackoverflow.com/questions/27573371/accessing-an-already-running-process-with-python – Thomas Weller Feb 22 '22 at 19:58
  • Basically: either you know very well how to do it - then you needn't ask the question, because you're a security researcher and have knowledge in hooking, patching and writing kernel mode drivers. Or you just don't do that. – Thomas Weller Feb 22 '22 at 20:01
  • This link I think has the direction I should go. I've built a wall around myself here. Not really interested in hacking and patching kernel drivers. – Daddy Feb 22 '22 at 20:06

0 Answers0