[OT] Console/pty on Windows
The following is a post by Brian Dessent on the MinGW-Users
mailing list. People thinking about vim and consoles/ptys on
Windows might find it interesting.
>> http://msdn2.microsoft.com/en-us/library/ms740141.aspx[following is from Brian Dessent on the MinGW-Users list]
> So how do I do a 'select' on stdin of the parent and the
> stdout of the child?
I'm not sure I quite understand the context here. If you just
want to spawn a child process and read its stdout (or write its
stdin) over a pipe, then you can just use the standard popen:
This is somewhat of an abstraction from the Win32 calls, so if you
want to see how to do it directly with Win32 then have a look at:
But if I'm understanding correctly that's not what you want -- you
have multiple read inputs that you need to multiplex? In that
case you will probably need to use WaitForMultipleObjects(), which
is somewhat of an analog to the POSIX select():
Note however that the list of types of objects that WFMO can
accept does not include files or pipes:
* Change notification
* Console input
* Memory resource notification
* Waitable timer
(also note that "Console input" means direct input from a console,
i.e. the user typed something. Consoles are sort of like the
Win32 equivalent of ptys, but they are not "pseudo" -- they
represent an actual console, i.e. what you see when you click on
"Command Prompt" in the start menu. If you have a child spawned
with stdin/stdout redirected then GetStdHandle returns a pipe
handle, so you can't use the console API on them in that case. I
suppose if you really wanted to be tricky you could achieve
something like a pty by creating a new console with its window
hidden off-screen, launching your child attached to that console,
and then using the Win32 console API to read and write to it.
This is, incidently, what the Console project
<http://sourceforge.net/projects/console/> does to provide a
prettier interface (multiple tabs, sane copy/paste, better font
selection, etc) for Win32 consoles while still having the programs
being run think they are attached to a real console, instead of a
In order to select on files and pipes, you have to use
asynchronous (aka overlapped) I/O, which is kind of like what
POSIX calls non-blocking I/O:
MSDN has an example of doing this with named pipes:
Note that Win32 named pipes are more like what POSIX calls fifos.
Win32 anonymous pipes are the kind that are usually used for
redirection and follow pretty closely to what POSIX calls a pipe.
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php