conin: utility for running native console programs in ttys

Skip to first unread message

Andy Koppe

Dec 12, 2009, 9:32:25 AM12/12/09
to mintty

I've created a small utility for running native console programs in
mintty and other terminals based on Cygwin ptys. This is for
interactive programs that otherwise don't work properly in ttys.

The source can be found at,
and a zipped executable is available at
(It's compiled with 'cc -std=c99 conin.c -lreadline -o conin -mwindows
-Os -s'.)

It can be used by simply prefixing the program to be run, e.g.:

$ conin C:/Python26/python

Conin works by creating a hidden console and connecting the child
program's stdin to that. It then translates keypresses coming in via
its own stdin and writes them to the console's input buffer using the
WriteConsoleInput function.

Readline is used to handle keyboard input, which means that all the
usual readline line editing facilities, including anything configured
in .inputrc, are available. It also recognises when the program wants
raw console input (scala is an example of that), and in that case
skips readline and passes input straight on.

The child program's stdout and stderr, meanwhile, are not connected to
the hidden console, and instead go more or less directly to the
terminal. That's because the Windows console API does not provide a
way to intercept console output before it's rendered to the console
screen buffer. This means that anything that depends on console-
specific output functions will still not work.

Nevertheless this approach seems to work at least for python, cmd.exe,
and scala. Please give it a go on any other problem cases you might
have come across, but keep in mind that this is little more than proof-
of-concept at the moment, with some big limitations:

- Non-ASCII characters are not supported.
- Raw mode only supports keys that translate to ASCII characters and
unmodified arrow keys.
- Ctrl+C kills the child process dead. (I've tried quite hard to
translate it to a "console ctrl event", but unfortunately without
- No documentation.

Let me know whether this seems useful and worth spending more time on.
Bug reports and enhancement suggestions welcome.


Andy Koppe

Jan 20, 2010, 2:46:09 PM1/20/10
to mintty

An updated version of the 'conin' utility for running native programs
that depend on stdin (but not stdout) being a console can be found at This adds locale/
charset support.


Reply all
Reply to author
0 new messages