I see two options: you can either run it as a separate process and indeed use subprocess
, such as
sp = subprocess.Popen(['./generate_name.py'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
sp.stdin.write("2\n")
sp.stdin.close()
answer = sp.stdout.read()
status = sp.wait()
or you take your script and exec
it. Before you do so, you can redirect sys.stdin
and sys.stdout
and you can capture and monitor all changes you make. This way, you can run it inside one process.