The goal is to open python terminal with pre-execution of some commands. In real life it's loading some modules and defines some variables, but here is a simplified version:
from subprocess import Popen, CREATE_NEW_CONSOLE
r=Popen("python",creationflags=CREATE_NEW_CONSOLE)
r.communicate(input=b"print(2+2)")
CREATE_NEW_CONSOLE is used, because otherwise terminal window doesn't appear (I run the code from IDE). The code above opens a python terminal window, but input doesn't get there. Trying some variations stops window from appearing, like:
r=Popen(["python","print(2+2)"],creationflags=CREATE_NEW_CONSOLE)
Or
r=Popen("python",creationflags=CREATE_NEW_CONSOLE, stdin=PIPE)
r.communicate(input=b"print(2+2)")
So what can be done to solve the problem?