Rumors of Cmd’s death have been greatly exaggerated
Windows really needs a public psuedoconsole API.<p>For the uninitiated: cmd.exe is the shell, like bash. conhost.exe is the terminal emulator, like xterm. bash or cmd (the shell) talks to the terminal via its standard input, output, and error file handles. Terminal handles are like full-duplex pipes, but richer<i>: they transmit all the information needed for interaction with the user. Each terminal handle has two ends: </i>master* and <i>slave</i>. The slave is the terminal to which cmd or bash talks; it basically emulates a teletype. The master handle allows for reading both in-band and out-of-band information from the slave terminal handle and supports special APIs that allow anyone with access to the master handle to fully emulate a terminal.<p>POSIX systems allow anyone to create master and slave terminal handles. When you start xterm, xterm calls openpty, gets master and slave handles, starts your shell with the slave handle, and uses the master terminal to get the information needed to draw characters.<p>There&#x27;s no equivalent for Windows. The only Windows program that can call the Windows equivalent of openpty is conhost, which ships with the operating system. It&#x27;s not possible for a <i>different</i> program to make a master-side terminal handle. There are two workarounds, which both suck: 1) use pipes, not console handles, and 2) make a hidden conhost.exe and scrape it. The former causes programs to think they&#x27;re being run non-interactively, with all sorts of negative side effects (like excessive buffering). The latter loses screen updates, is inefficient, and is generally awful.<p>Microsoft could easily make this situation much better by opening the protocol that conhost uses to communicate with the kernel. If any program can create a console handle, it&#x27;s much easier to implement things like ssh daemons, Cygwin, and terminal emulators that suck less than conhost.<p>...<p>* As an aside: when bash talks to xterm, it uses <i>in-band signaling</i> (mostly: see termios): it sends control code sequences, which xterm understands as &quot;move cursor to 3,3&quot; and &quot;set color to green&quot;. By contrast, when cmd communicates to conhost, it uses <i>out-of-band signaling</i>: it uses special API functions to move the cursor and set the text color.