I've seen similar questions such as this one: keep multiple console windows open from batch.
However, I have a different situation. I do not want to run a different script in a different console window. My idea is to have socket running as a server and accepting all connections. When a connection is accepted, a new console window is created, and all in-coming and out-going data is shown there. Is that even possible?
A process can only be attached to one console (i.e. instance of conhost.exe) at a time, and a console with no attached processes automatically closes. You would need to spawn a child process with
creationflags=CREATE_NEW_CONSOLE
.The following demo script requires Windows Python 3.3+. It spawns two worker processes and duplicates each socket connection into the worker via
socket.share
andsocket.fromshare
. The marshaled socket information is sent to the child'sstdin
over a pipe. After loading the socket connection, the pipe is closed andCONIN$
is opened assys.stdin
to read standard input from the console.