1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import subprocess
class Interactor: def __init__(self): self.init_output = ""
def response(self, query: str): ...
def start(self, cmd): with subprocess.Popen( cmd, text=True, stdin=-1, stdout=-1, ) as p: if self.init_output: p.stdin.write(self.init_output + "\n") p.stdin.flush() while resp := self.response(p.stdout.readline()): p.stdin.write(resp + "\n") p.stdin.flush()
|