3 [![Build Status](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty)](https://dev.azure.com/vscode/node-pty/_build/latest?definitionId=11)
5 `forkpty(3)` bindings for node.js. This allows you to fork processes with pseudoterminal file descriptors. It returns a terminal object which allows reads and writes.
9 - Writing a terminal emulator (eg. via [xterm.js](https://github.com/sourcelair/xterm.js)).
10 - Getting certain programs to *think* you're a terminal, such as when you need a program to send you control sequences.
12 `node-pty` supports Linux, macOS and Windows. Windows support is possible by utilizing the [Windows conpty API](https://blogs.msdn.microsoft.com/commandline/2018/08/02/windows-command-line-introducing-the-windows-pseudo-console-conpty/) on Windows 1809+ and the [winpty](https://github.com/rprichard/winpty) library in older version.
16 `node-pty` powers many different terminal emulators, including:
18 - [Microsoft Visual Studio Code](https://code.visualstudio.com)
19 - [Hyper](https://hyper.is/)
20 - [Upterm](https://github.com/railsware/upterm)
21 - [Script Runner](https://github.com/ioquatix/script-runner) for Atom.
22 - [Theia](https://github.com/theia-ide/theia)
23 - [FreeMAN](https://github.com/matthew-matvei/freeman) file manager
24 - [atom-xterm](https://atom.io/packages/atom-xterm) - Atom plugin for providing terminals inside your Atom workspace.
25 - [Termination](https://atom.io/packages/termination) - Another Atom plugin that provides terminals inside your Atom workspace.
26 - [electerm](https://github.com/electerm/electerm) Terminal/ssh/sftp client(linux, mac, win).
27 - [Extraterm](http://extraterm.org/)
28 - [Wetty](https://github.com/krishnasrinivas/wetty) Browser based Terminal over HTTP and HTTPS
30 Do you use node-pty in your application as well? Please open a [Pull Request](https://github.com/Tyriar/node-pty/pulls) to include it here. We would love to have it in our list.
35 var os = require('os');
36 var pty = require('node-pty');
38 var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
40 var ptyProcess = pty.spawn(shell, [], {
44 cwd: process.env.HOME,
48 ptyProcess.on('data', function(data) {
49 process.stdout.write(data);
52 ptyProcess.write('ls\r');
53 ptyProcess.resize(100, 40);
54 ptyProcess.write('ls\r');
60 # Install dependencies and build C++
62 # Compile TypeScript -> JavaScript
71 sudo apt install -y make python build-essential
74 The following are also needed:
80 `npm install` requires some tools to be present in the system like Python and C++ compiler. Windows users can easily install them by running the following command in PowerShell as administrator. For more information see https://github.com/felixrieseberg/windows-build-tools:
83 npm install --global --production windows-build-tools
86 The following are also needed:
88 - [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk) - only the "Desktop C++ Apps" components are needed to be installed
93 [The wiki](https://github.com/Microsoft/node-pty/wiki/Debugging) contains instructions for debugging node-pty.
97 All processes launched from node-pty will launch at the same permission level of the parent process. Take care particularly when using node-pty inside a server that's accessible on the internet. We recommend launching the pty inside a container to protect your host machine.
101 Note that node-pty is not thread safe so running it across multiple worker threads in node.js could cause issues.
105 Automatic flow control can be enabled by either providing `handleFlowControl = true` in the constructor options or setting it later on:
108 const PAUSE = '\x13'; // XOFF
109 const RESUME = '\x11'; // XON
111 const ptyProcess = pty.spawn(shell, [], {handleFlowControl: true});
113 // flow control in action
114 ptyProcess.write(PAUSE); // pty will block and pause the slave program
116 ptyProcess.write(RESUME); // pty will enter flow mode and resume the slave program
118 // temporarily disable/re-enable flow control
119 ptyProcess.handleFlowControl = false;
121 ptyProcess.handleFlowControl = true;
124 By default `PAUSE` and `RESUME` are XON/XOFF control codes (as shown above). To avoid conflicts in environments that use these control codes for different purposes the messages can be customized as `flowControlPause: string` and `flowControlResume: string` in the constructor options. `PAUSE` and `RESUME` are not passed to the underlying pseudoterminal if flow control is enabled.
128 ### Powershell gives error 8009001d
130 > Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.
132 This happens when PowerShell is launched with no `SystemRoot` environment variable present.
134 ### ConnectNamedPipe failed: Windows error 232
136 This error can occur due to anti-virus software intercepting winpty from creating a pty. To workaround this you can exclude this file from your anti-virus scanning `node-pty\build\Release\winpty-agent.exe`
140 This project is forked from [chjj/pty.js](https://github.com/chjj/pty.js) with the primary goals being to provide better support for later Node.JS versions and Windows.
144 Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).<br>
145 Copyright (c) 2016, Daniel Imms (MIT License).<br>
146 Copyright (c) 2018, Microsoft Corporation (MIT License).