Reputation: 751
I am trying to understand how to create a new console to print stuff, that is, have more than one stdout available. After reading some questions, I only managed to do this:
from subprocess import Popen, CREATE_NEW_CONSOLE
handle = Popen("cmd", stdin=PIPE, creationflags=CREATE_NEW_CONSOLE)
i.write(b'hello')
But the message doesnt show up on the new console.
What are my options?
Upvotes: 1
Views: 881
Reputation: 751
Altough I didnt find how to directly create new sdtouts from new consoles, I managed to get the same effect using inter-process communication pipes.
from multiprocessing.connection import Client
import sys
address = '\\\\.\pipe\\new_console'
conn = Client(address)
while True:
print(conn.recv())
from multiprocessing.connection import Listener
from subprocess import Popen, CREATE_NEW_CONSOLE
address = '\\\\.\pipe\\new_console'
listener = Listener(address)
def new_console():
Popen("python new_console.py", creationflags=CREATE_NEW_CONSOLE)
return listener.accept()
c1 = new_console()
c1.send("console 1 ready")
c2 = new_console()
c2.send("console 2 ready")
Further improvements include sending input from new consoles to the main process, using select in the loop.
Upvotes: 1