Using conhost as a PTY host? Sorta? #23323

Open
opened 2026-01-31 08:38:53 +00:00 by claunia · 0 comments
Owner

Originally created by @prettydiff on GitHub (Jun 1, 2025).

Windows Terminal version

1.22.11141.0

Windows build number

10.0.26100.0

Other Software

This is a re-post from the PowerShell repository per their suggestion: https://github.com/PowerShell/PowerShell/issues/25625

  • bash.exe from git-svm for windows
  • cmd.exe
  • PowerShell v7.5.1
  • PowerShell v5.1
  • Node.js 23.x.x

Steps to reproduce

I am using conhost.exe as a PTY to execute and stream various shells to JavaScript. I am executing conhost as a Node.js child process. Here are two examples of execution:

child_process.spawn(
    "c:\\windows\\system32\\conhost.exe",
    ["c:\\program files\\powershell\\7\\pwsh.exe"],
    {
        env: process.env,
        windowsHide: true
    });

child_process.spawn(
    "c:\\windows\\system32\\conhost.exe",
    ["c:\\program files\\git\\bin\\bash.exe"],
    {
        env: process.env,
        windowsHide: true
    });

Challenges

I am having trouble finding documentation for a ConHost API, but I was able to find a MSDN page listing a bunch of C# functions for modifying ConHost behavior. I did find the PowerShell 7 API documentation, but its only building custom exe files with C# and .NET. I work in a secure environment where I cannot build, deploy, or pull in arbitrary executable files not already part of an approved Windows image.

If I could arbitrarily execute binaries to solve for these conerns I would just use XTERM.js which already solves for these concerns with its own internal PTY and is already a Microsoft project. If this double prompt issue is resolved XTERM.js can become functionally obsolete aside from convenience and shell resize.

Expected Behavior

The PTY stdout stream to third party applications behaves identically as it does for MiscroSoft's TTY applications.

Actual Behavior

  • cmd.exe - works perfectly
  • PowerShell v5.1 - Displays the prompt followed by \r\n>> with some ANSI control characters mixed in.
  • PowerShell v7.5.1 - Same as above but the hidden ANSI control sequences are different.
  • Bash.exe - One completely normal prompt followed by a second completely separate and identical prompt as though the user pressed the "enter" key to generate multiple lines in the shell.

Problem Example 1 - PowerShell v7.5.1 (partial double prompt with visible characters)

PS C:\Users\info\webserver> $psGet=Get-Host
>> 

Problem Example 1 - PowerShell v7.5.1 (partial double prompt with ANSI control characters)

PS C:\\Users\\info\\webserver> \u001b[92m$psGet\u001b[90m=\u001b[93mGet-Host\u001b[37m\r\n>> \r\n\u001b[?25h

Problem Example 2 - PowerShell v7.5.1 (partial double prompt with visible characters)

PS C:\Users\info\webserver> 
>> 

Problem Example 2 - PowerShell v7.5.1 ( partial double prompt with ANSI control characters)

PS C:\\Users\\info\\webserver> \u001b[37m\r\n>> \u001b[38;29H\u001b[?25h

Problem Example 3 - Bash.exe (double prompt)

info@DESKTOP-E98HNIV MINGW64 ~/webserver (certs)
$ 

info@DESKTOP-E98HNIV MINGW64 ~/webserver (certs)
$ 

Except for the double prompt this works perfectly and I can stream shell access across a network into a web browser. ConHost and/or Node.js even successfully executes these shells in a headless mode without use of an undocumented headless option for ConHost. The shells themselves do not output any error messaging. Even complex things like Vim and line wrapping displays correctly.

This defect is only present on the STDOUT stream from the PTY connection. It is not present in the TTY of a graphical terminal interface. This means the problem cannot be reproduced using PowerShell as a desktop application even when PowerShell is the executing shell. I suspect any means to call conhost without using a TTY interface would reproduce this.

Originally created by @prettydiff on GitHub (Jun 1, 2025). ### Windows Terminal version 1.22.11141.0 ### Windows build number 10.0.26100.0 ### Other Software This is a re-post from the PowerShell repository per their suggestion: https://github.com/PowerShell/PowerShell/issues/25625 * bash.exe from git-svm for windows * cmd.exe * PowerShell v7.5.1 * PowerShell v5.1 * Node.js 23.x.x ### Steps to reproduce I am using conhost.exe as a PTY to execute and stream various shells to JavaScript. I am executing conhost as a Node.js child process. Here are two examples of execution: ``` child_process.spawn( "c:\\windows\\system32\\conhost.exe", ["c:\\program files\\powershell\\7\\pwsh.exe"], { env: process.env, windowsHide: true }); child_process.spawn( "c:\\windows\\system32\\conhost.exe", ["c:\\program files\\git\\bin\\bash.exe"], { env: process.env, windowsHide: true }); ``` #### Challenges I am having trouble finding documentation for a ConHost API, but I was able to find a MSDN page listing a bunch of C# functions for modifying ConHost behavior. I did find the PowerShell 7 API documentation, but its only building custom exe files with C# and .NET. I work in a secure environment where I cannot build, deploy, or pull in arbitrary executable files not already part of an approved Windows image. If I could arbitrarily execute binaries to solve for these conerns I would just use XTERM.js which already solves for these concerns with its own internal PTY and is already a Microsoft project. If this double prompt issue is resolved XTERM.js can become functionally obsolete aside from convenience and shell resize. ### Expected Behavior The PTY stdout stream to third party applications behaves identically as it does for MiscroSoft's TTY applications. ### Actual Behavior * cmd.exe - works perfectly * PowerShell v5.1 - Displays the prompt followed by `\r\n>> ` with some ANSI control characters mixed in. * PowerShell v7.5.1 - Same as above but the hidden ANSI control sequences are different. * Bash.exe - One completely normal prompt followed by a second completely separate and identical prompt as though the user pressed the "enter" key to generate multiple lines in the shell. #### Problem Example 1 - PowerShell v7.5.1 (partial double prompt with visible characters) ``` PS C:\Users\info\webserver> $psGet=Get-Host >> ``` #### Problem Example 1 - PowerShell v7.5.1 (partial double prompt with ANSI control characters) ``` PS C:\\Users\\info\\webserver> \u001b[92m$psGet\u001b[90m=\u001b[93mGet-Host\u001b[37m\r\n>> \r\n\u001b[?25h ``` #### Problem Example 2 - PowerShell v7.5.1 (partial double prompt with visible characters) ``` PS C:\Users\info\webserver> >> ``` #### Problem Example 2 - PowerShell v7.5.1 ( partial double prompt with ANSI control characters) ``` PS C:\\Users\\info\\webserver> \u001b[37m\r\n>> \u001b[38;29H\u001b[?25h ``` #### Problem Example 3 - Bash.exe (double prompt) ``` info@DESKTOP-E98HNIV MINGW64 ~/webserver (certs) $ info@DESKTOP-E98HNIV MINGW64 ~/webserver (certs) $ ``` Except for the double prompt this works perfectly and I can stream shell access across a network into a web browser. ConHost and/or Node.js even successfully executes these shells in a headless mode without use of an undocumented *headless* option for ConHost. The shells themselves do not output any error messaging. Even complex things like Vim and line wrapping displays correctly. This defect is only present on the STDOUT stream from the PTY connection. It is not present in the TTY of a graphical terminal interface. **This means the problem cannot be reproduced using PowerShell as a desktop application even when PowerShell is the executing shell.** I suspect any means to call conhost without using a TTY interface would reproduce this.
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 08:38:53 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#23323