Using conhost as a PTY host? Sorta? #19003
Replies: 4 comments
-
conhost is not a PTY, it's a terminal. As part of an implementation detail, it just so happens to also be used for implementing Microsoft's PTY API at the moment ( So, if you're not using
That's the way Your I feel like you left out some details about your issue... For what it's worth, this issue is likely something we cannot help with, because the only supported way to get a PTY is via |
Beta Was this translation helpful? Give feedback.
-
@lhecker I am executing in this manner: c:\windows\system32\conhost.exe 'c:\program files\powershell\7\pwsh.exe' If I execute PowerShell 7 through a third party application like Node without a PTY I can execute simple tasks like "ls" and I get back beautiful formatted output with all the ANSI control characters and formatting. It will works perfectly without a PTY on simple things only. When I execute VIM or exceed the column width of the shell on input the shell locks. When I do execute PowerShell through conhost.exe then absolutely everything works perfectly, but I get the double prompt. If you think I am leaving anything out please let me know I am eager to resolve these concerns and will disclose all I have attempted on this effort. Here is my currently working code with some descriptions: In that code sample I am passing in absolute file paths for the pty and shell, such as:
The commented block on lines 31-49 is the preamble for using Microsoft's node-pty solution, which I cannot use at work because it makes use of unapproved binaries. I suspect node-pty does make use of CreatePseudoConsole in the binaries it generates. The input is streamed to the shell from a network socket on line 68 or 72. The output from the shell is streamed back to the network socket on line 76 via line 103. |
Beta Was this translation helpful? Give feedback.
-
Part of the problem is: conhost doesn't automatically run in PTY mode when you launch it like that. You aren't passing the right set of arguments ( If you aren't passing those, you are not guaranteed to be getting a hosted PTY session; rather, you are likely to be getting an unsupported third thing. |
Beta Was this translation helpful? Give feedback.
-
To be entirely clear: this is not a supported API surface. If you can call native functions in native Microsoft libraries, you should be using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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: PowerShell/PowerShell#25625
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:
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
\r\n>>
with some ANSI control characters mixed in.Problem Example 1 - PowerShell v7.5.1 (partial double prompt with visible characters)
Problem Example 1 - PowerShell v7.5.1 (partial double prompt with ANSI control characters)
Problem Example 2 - PowerShell v7.5.1 (partial double prompt with visible characters)
Problem Example 2 - PowerShell v7.5.1 ( partial double prompt with ANSI control characters)
Problem Example 3 - Bash.exe (double prompt)
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.
Beta Was this translation helpful? Give feedback.
All reactions