Redirect IO of process to Windows socket

前端 未结 4 536
轻奢々
轻奢々 2021-01-14 02:50

I am new to winsock, I tried to write a server socket that accepts new connection, then it calls an external executable file. How can we redirect the stdin and stdout of the

4条回答
  •  遥遥无期
    2021-01-14 03:36

    Actually, you can redirect IO to sockets. Just make sure you open the socket with WSASocket instead of socket(), and do NOT specify the WSA_FLAG_OVERLAPPED.

    The reason for this is a bit involved. Any "Standard Handles" that you supply to CreateProcess for I/O redirection must be non-overlapped (i.e, do not support overlapped I/O). sockets on Windows are opened overlapped when created with socket() and non-overlapped if created as above with WSASocket.

    Also make sure you set bInheritHandles to TRUE in the StartupInfo

提交回复
热议问题