How to run ConPTY terminal from node.js pm2?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
In node.js I use PTY terminal to run shells and capture its output text. Something like this
const pty = require('node-pty');
const AnsiTerminal = require('node-ansiterminal').AnsiTerminal;
const AnsiParser = require('node-ansiparser');
const Convert = require('ansi-to-html');
const shell = ptyProcess = pty.spawn('powershell.exe', ['-executionpolicy', 'remotesigned', '-File', 'test.ps1'], { name: 'test', cols: terminal_columns, rows: 30, cwd: __dirname, env: process.env });
var convert = new Convert({
newline:true
});
const terminal_columns = 160;
var terminal = new AnsiTerminal(terminal_columns, 30, 500);
var parser = new AnsiParser(terminal);
ptyProcess.onData((data) => {
const msg = data.toString();
parser.parse(msg);
const str = terminal.toString().trim() + "\n\n";
var html_str = convert.toHtml(str);
});
ptyProcess.onExit(function(data) {
// exit event
});
When I start the node program on a powershell terminal manually it works fine. But if I use pm2 to start the node program, it throws an error
Cannot create process, error code: 267
But if I create a regular shell like powershell.exe instead of the PTY one, it works fine.
How can I get pm2 to work with PTY?
Thanks
How could we reproduce this issue?
Run the above code from pm2.
Supporting information
Windows 10, node.js 10 latest
$ pm2 report
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the shown node-pty PowerShell example under PM2 on Windows 10 and compare it with running the same program manually. Investigate the ConPTY failure reporting error code 267, then verify that the PTY process starts successfully under PM2 without changing the regular-shell behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, powershell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100