From 7b1098d90d3244ba8982faf52f4725630028bdbb Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Thu, 1 Jun 2023 23:42:53 +0200 Subject: [PATCH] Before adding `universal_newlines=True` to `meta.py` subprocesses --- meta.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/meta.py b/meta.py index 928d0b1..4fce35d 100755 --- a/meta.py +++ b/meta.py @@ -2,15 +2,31 @@ import subprocess, ast -p = subprocess.Popen('./verifier.py', - stdout = subprocess.PIPE, - stdin = subprocess.PIPE) +verifier, prover = [subprocess.Popen(f'./{program}.py', stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.DEVNULL) for program in ('verifier', 'prover')] -lines = p.communicate()[0].decode('ascii').splitlines() -print(lines) -protocolInitializationPhaseId = ast.literal_eval(lines[0].split('=')[1]) +def getProgramLine(program): + return program.stdout.readline().decode('ascii') + +def getOutput(line): + return ast.literal_eval(line.split('=')[1]) + +def getProgramOutput(program): + return getOutput(getProgramLine(program)) + +protocolInitializationPhaseId = getProgramOutput(verifier) print(f'{protocolInitializationPhaseId=}') -protocolExecutionPhaseId = ast.literal_eval(lines[1].split('=')[1]) +protocolExecutionPhaseId = getProgramOutput(verifier) print(f'{protocolExecutionPhaseId=}') +prover.stdin.write(protocolInitializationPhaseId.encode('ascii') + b'\n') +#getProgramLine(prover) +#getProgramLine(prover) +prover.stdin.write(protocolExecutionPhaseId.encode('ascii') + b'\n') +#prover.stdin.close() +#verifier.stdin.write(b"test\n") + +#lines = prover.communicate()[0].decode('ascii').splitlines() +#print(lines) + +print(getProgramLine(prover))