Skip to content

child_pty on Windows

Enno Boland edited this page Nov 2, 2016 · 1 revision

Windows Port

This document describes the challenges to take to port child_pty to windows.

the child_pty idea

Being a long time node adapter I used pty.js for a long time. Pty.js comes with windows support and was an early child of the node.js world. Unfortunately this results in some outdated usage of the API and massive usage of native code.

child_pty on the other hand tries to use nodes APIs as much as possible and avoids implementation of functionality as much as possible. Child_pty leaves process handling completely to the child_process module and only cares about creating the pty and wiring it up with up with the child.

How child_pty works

child_pty is about 100 loc of Javascript code and another 100 loc of C code. So it is quite minimal. The JS code uses it's own Socket variant (called PtyRwStream). It's purpose is to ignore some expected errors on destroy.

The C part of the program does nothing but opening and resizing a pty. Execwrapper takes care, that the slave side of the terminal is configured before the real program is executed.

Steps to take

For windows there's the cool but hackish winpty library. It provides gyp files and integrates nicely with node applications. It's already integrated with the windows branch of child_pty.

Unfortunately winpty provides its own C functions to spawn processes and the overall live cycle of a winpty spawn process differs from the one in child_pty.

So, basicly porting child_pty to windows means giving up much of its simplicity.

Clone this wiki locally