Loading ...
Sorry, an error occurred while loading the content.

[OT] Console/pty on Windows

Expand Messages
  • Suresh Govindachar
    Hello, 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
    Message 1 of 1 , Nov 5, 2007
    • 0 Attachment
      Hello,

      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.

      --Suresh

      >> http://msdn2.microsoft.com/en-us/library/ms740141.aspx
      >
      > So how do I do a 'select' on stdin of the parent and the
      > stdout of the child?

      [following is from Brian Dessent on the MinGW-Users list]

      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:
      <http://msdn2.microsoft.com/en-us/library/96ayss4b(VS.80).aspx>.
      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:
      <http://msdn2.microsoft.com/en-us/library/ms682499.aspx>.

      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():
      <http://msdn2.microsoft.com/en-us/library/ms687025.aspx>.
      Note however that the list of types of objects that WFMO can
      accept does not include files or pipes:

      * Change notification
      * Console input
      * Event
      * Memory resource notification
      * Mutex
      * Process
      * Semaphore
      * Thread
      * 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
      pipe.)

      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:
      <http://msdn2.microsoft.com/en-us/library/ms686358.aspx>.
      MSDN has an example of doing this with named pipes:
      <http://msdn2.microsoft.com/en-us/library/aa365603.aspx>.
      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
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.