new.py
print("Gib number")
x = input()
print('numba is ', x)
launcher.py
import subprocess as sp
p = sp.Popen(['python', 'new.py'], stdout=sp.PIPE, stderr=sp.STDOUT, stdin=sp.PIPE, text=True)
while True:
line = p.stdout.readline()
print('line is', line)
p.stdin.write('10')
p.wait()
Why can’t the launcher.py
read from new.py
‘s stdout on second iteration?
However, If I use pwntools
to launch the same file, it succeeds, albeit with an error on sendline
on second iteration, which is understandable because presumably the stdin of the new.py
is closed by then.
_launcher.py
from pwn import process
p = process(['python', 'new.py'], stderr=process.PTY, stdout=process.PTY)
while True:
output = p.recv()
print('line is', output)
p.sendline(10) # Sends the answer with a newline
p.wait()
What mechanism does pwntools
‘s recv
and sendline
use and how can I launch the new.py
without having to use pwntools
?
Please provide any relevant readings as well.
7