2016-03-30 07:59:32 +00:00
|
|
|
# winpty
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-06-14 05:03:47 +00:00
|
|
|
[![Build Status](https://tea-ci.org/api/badges/rprichard/winpty/status.svg)](https://tea-ci.org/rprichard/winpty)
|
|
|
|
|
2012-12-20 11:18:05 +00:00
|
|
|
winpty is a Windows software package providing an interface similar to a Unix
|
|
|
|
pty-master for communicating with Windows console programs. The package
|
|
|
|
consists of a library (libwinpty) and a tool for Cygwin and MSYS for running
|
|
|
|
Windows console programs in a Cygwin/MSYS pty.
|
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
The software works by starting the `winpty-agent.exe` process with a new,
|
2012-12-20 11:18:05 +00:00
|
|
|
hidden console window, which bridges between the console API and terminal
|
|
|
|
input/output escape codes. It polls the hidden console's screen buffer for
|
|
|
|
changes and generates a corresponding stream of output.
|
|
|
|
|
|
|
|
The Unix adapter allows running Windows console programs (e.g. CMD, PowerShell,
|
2016-03-30 07:59:32 +00:00
|
|
|
IronPython, etc.) under `mintty` or Cygwin's `sshd` with
|
2012-12-20 11:18:05 +00:00
|
|
|
properly-functioning input (e.g. arrow and function keys) and output (e.g. line
|
|
|
|
buffering). The library could be also useful for writing a non-Cygwin SSH
|
|
|
|
server.
|
|
|
|
|
2016-03-30 08:20:55 +00:00
|
|
|
## Supported Windows versions
|
|
|
|
|
|
|
|
winpty runs on Windows XP through Windows 10, including server versions. It
|
|
|
|
can be compiled into either 32-bit or 64-bit binaries.
|
|
|
|
|
2016-04-05 07:36:06 +00:00
|
|
|
## Cygwin/MSYS adapter (`winpty.exe`)
|
2016-03-30 08:20:55 +00:00
|
|
|
|
|
|
|
### Prerequisites
|
2012-12-20 11:18:05 +00:00
|
|
|
|
|
|
|
You need the following to build winpty:
|
|
|
|
|
|
|
|
* A Cygwin or MSYS installation
|
|
|
|
* GNU make
|
2016-03-30 07:59:32 +00:00
|
|
|
* A MinGW g++ toolchain capable of compiling C++11 code to build `winpty.dll`
|
|
|
|
and `winpty-agent.exe`
|
2016-04-05 07:36:06 +00:00
|
|
|
* A g++ toolchain targeting Cygwin or MSYS to build `winpty.exe`
|
2012-12-20 11:18:05 +00:00
|
|
|
|
|
|
|
Winpty requires two g++ toolchains as it is split into two parts. The
|
2016-03-30 07:59:32 +00:00
|
|
|
`winpty.dll` and `winpty-agent.exe` binaries interface with the native
|
2016-02-26 06:10:53 +00:00
|
|
|
Windows command prompt window so they are compiled with the native MinGW
|
2016-04-05 07:36:06 +00:00
|
|
|
toolchain. The `winpty.exe` binary interfaces with the MSYS/Cygwin terminal so
|
2016-02-26 06:10:53 +00:00
|
|
|
it is compiled with the MSYS/Cygwin toolchain.
|
2012-12-20 11:18:05 +00:00
|
|
|
|
|
|
|
MinGW appears to be split into two distributions -- MinGW (creates 32-bit
|
|
|
|
binaries) and MinGW-w64 (creates both 32-bit and 64-bit binaries). Either
|
2016-02-26 06:10:53 +00:00
|
|
|
one is generally acceptable.
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-03-30 08:20:55 +00:00
|
|
|
#### Cygwin packages
|
2012-12-20 11:18:05 +00:00
|
|
|
|
|
|
|
The default g++ compiler for Cygwin targets Cygwin itself, but Cygwin also
|
2016-02-26 06:10:53 +00:00
|
|
|
packages MinGW-w64 compilers. As of this writing, the necessary packages are:
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
* Either `mingw64-i686-gcc-g++` or `mingw64-x86_64-gcc-g++`. Select the
|
2016-02-26 06:10:53 +00:00
|
|
|
appropriate compiler for your CPU architecture.
|
2016-03-30 07:59:32 +00:00
|
|
|
* `gcc-g++`
|
|
|
|
* `make`
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-02-26 06:10:53 +00:00
|
|
|
As of this writing (2016-01-23), only the MinGW-w64 compiler is acceptable.
|
2016-03-30 07:59:32 +00:00
|
|
|
The MinGW compiler (e.g. from the `mingw-gcc-g++` package) is no longer
|
2016-02-26 06:10:53 +00:00
|
|
|
maintained and is too buggy.
|
|
|
|
|
2016-03-30 08:20:55 +00:00
|
|
|
#### MSYS packages
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
For the original MSYS, use the `mingw-get` tool (MinGW Installation Manager),
|
2015-09-30 08:34:16 +00:00
|
|
|
and select at least these components:
|
2015-09-30 09:18:22 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
* `mingw-developer-toolkit`
|
|
|
|
* `mingw32-base`
|
|
|
|
* `mingw32-gcc-g++`
|
|
|
|
* `msys-base`
|
|
|
|
* `msys-system-builder`
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
When running `./configure`, make sure that `mingw32-g++` is in your
|
|
|
|
`PATH`. It will be in the `C:\MinGW\bin` directory.
|
2015-09-30 08:34:16 +00:00
|
|
|
|
2016-03-30 08:20:55 +00:00
|
|
|
#### MSYS2 packages
|
2015-11-08 06:18:08 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
For MSYS2, use `pacman` and install at least these packages:
|
2015-09-30 09:18:22 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
* `msys/gcc`
|
|
|
|
* `mingw32/mingw-w64-i686-gcc` or `mingw64/mingw-w64-x86_64-gcc`. Select
|
2015-09-30 08:34:16 +00:00
|
|
|
the appropriate compiler for your CPU architecture.
|
2016-03-30 07:59:32 +00:00
|
|
|
* `make`
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-05-20 22:16:23 +00:00
|
|
|
MSYS2 provides three start menu shortcuts for starting MSYS2:
|
|
|
|
|
|
|
|
* MinGW-w64 Win32 Shell
|
|
|
|
* MinGW-w64 Win64 Shell
|
|
|
|
* MSYS2 Shell
|
|
|
|
|
|
|
|
To build winpty, use the MinGW-w64 {Win32,Win64} shortcut of the architecture
|
|
|
|
matching MSYS2. These shortcuts will put the g++ compiler from the
|
|
|
|
`{mingw32,mingw64}/mingw-w64-{i686,x86_64}-gcc` packages into the `PATH`.
|
|
|
|
|
|
|
|
Alternatively, instead of installing `mingw32/mingw-w64-i686-gcc` or
|
|
|
|
`mingw64/mingw-w64-x86_64-gcc`, install the `mingw-w64-cross-gcc` and
|
|
|
|
`mingw-w64-cross-crt-git` packages. These packages install cross-compilers
|
|
|
|
into `/opt/bin`, and then any of the three shortcuts will work.
|
|
|
|
|
2016-03-30 08:20:55 +00:00
|
|
|
### Building the Unix adapter
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-04-05 07:50:52 +00:00
|
|
|
In the project directory, run `./configure`, then `make`, then `make install`.
|
|
|
|
By default, winpty is installed into `/usr/local`. Pass `PREFIX=<path>` to
|
|
|
|
`make install` to override this default.
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-03-30 08:20:55 +00:00
|
|
|
### Using the Unix adapter
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
To run a Windows console program in `mintty` or Cygwin `sshd`, prepend
|
2016-04-05 07:36:06 +00:00
|
|
|
`winpty` to the command-line:
|
2012-12-20 11:18:05 +00:00
|
|
|
|
2016-04-05 07:36:06 +00:00
|
|
|
$ winpty powershell
|
|
|
|
Windows PowerShell
|
|
|
|
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
|
|
|
|
|
|
|
|
PS C:\rprichard\proj\winpty> 10 + 20
|
2012-12-20 11:18:05 +00:00
|
|
|
30
|
2016-04-05 07:36:06 +00:00
|
|
|
PS C:\rprichard\proj\winpty> exit
|
2015-10-01 08:17:38 +00:00
|
|
|
|
2016-03-30 08:20:55 +00:00
|
|
|
## Embedding winpty / MSVC compilation
|
|
|
|
|
|
|
|
See `src/include/winpty.h` for the prototypes of functions exported by
|
|
|
|
`winpty.dll`.
|
|
|
|
|
2016-04-05 07:36:06 +00:00
|
|
|
Only the `winpty.exe` binary uses Cygwin; all the other binaries work without
|
2016-03-30 08:20:55 +00:00
|
|
|
it and can be compiled with either MinGW or MSVC. To compile using MSVC,
|
|
|
|
download gyp and run `gyp -I configurations.gypi` in the `src` subdirectory.
|
|
|
|
This will generate a `winpty.sln` and associated project files. See the
|
|
|
|
`src/winpty.gyp` and `src/configurations.gypi` files for notes on dealing with
|
|
|
|
MSVC versions and different architectures.
|
|
|
|
|
|
|
|
Compiling winpty with MSVC currently requires MSVC 2013 or newer.
|
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
## Debugging winpty
|
2015-10-01 08:17:38 +00:00
|
|
|
|
|
|
|
winpty comes with a tool for collecting timestamped debugging output. To use
|
|
|
|
it:
|
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
1. Run `winpty-debugserver.exe` on the same computer as winpty.
|
|
|
|
2. Set the `WINPTY_DEBUG` environment variable to `trace` for the
|
2016-04-05 07:36:06 +00:00
|
|
|
`winpty.exe` process and/or the process using `libwinpty.dll`.
|
2015-10-01 08:17:38 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
winpty also recognizes a `WINPTY_SHOW_CONSOLE` environment variable. Set it
|
2015-10-01 08:17:38 +00:00
|
|
|
to 1 to prevent winpty from hiding the console window.
|
2015-11-08 06:37:25 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
## Copyright
|
2015-11-08 06:37:25 +00:00
|
|
|
|
2016-03-30 07:59:32 +00:00
|
|
|
This project is distributed under the MIT license (see the `LICENSE` file in
|
2015-11-08 06:37:25 +00:00
|
|
|
the project root).
|
|
|
|
|
|
|
|
By submitting a pull request for this project, you agree to license your
|
|
|
|
contribution under the MIT license to this project.
|