Replies: 6 comments
-
Beta Was this translation helpful? Give feedback.
-
Thanks for expressing appreciation for that document! You know, this is tickling a memory of handle inheritance causing us some significant trouble in the past. While I go look for the change we made on the OS intended to make this better, could you try setting Enabling the use of |
Beta Was this translation helpful? Give feedback.
-
A-ha! We did do some work to improve handle inheritance, but only if the inherited handles were console handles (so: the spawned application would connect to its parent's stdin/stdout even if it was supposed to be using a pseudoconsole) //
// If we are establishing a Pseudoterminal Connection, close
// any in/out/err handles that may have been copied from the parent.
// We will re-make new connections to the given PTY instead of
// using the automatically inherited handles.
//
if ((ProcessParameters->ConsoleFlags & CONSOLE_USING_PTY_REFERENCE) != 0)
{
ConsoleCloseIfConsoleHandle(&ProcessParameters->StandardInput);
ConsoleCloseIfConsoleHandle(&ProcessParameters->StandardOutput);
ConsoleCloseIfConsoleHandle(&ProcessParameters->StandardError);
} We didn't do the same for all other inherited handles, so... I'm going to file a bug on the docs to make sure we document the need for |
Beta Was this translation helpful? Give feedback.
-
It's not handle inheritance.
Maybe I'm missing something, but it seems to me that the pseudoconsole case is like the latter three scenarios (i.e. a new console or no console). If so, then the implementation of |
Beta Was this translation helpful? Give feedback.
-
@DHowett, thanks for your answer! Yes, your suggestion seems to work. I'll perform some experiments this week to see if it covers my use case, and let you know if there are any additional questions. For now, I guess we could close the issue? Or would you like for it to stay open until the documentation changes are made? |
Beta Was this translation helpful? Give feedback.
-
That's a disappointing resolution. If a child process isn't getting spawned with the same console as the parent, the system simply shouldn't duplicate the parent's standard I/O handles to the child. It should work the same way as |
Beta Was this translation helpful? Give feedback.
-
I am working on an application which creates a Windows pseudoconsole (using the ConPTY API, according to the official manual which is really good).
It starts a PowerShell session (for test), and shows everything ConPTY sends from that session via the pseudoconsole, and everything works really well. Until I redirect the parent program output to anywhere.
Here's my full code listing for reference.
So, if I start this program from terminal or from an IDE, it works (and tells how much data it has read from the PTY pipe). But if I start it with output redirected (e.g.
myprogram.exe > C:\Temp\somefile.txt
, or evenmyprogram.exe | out-host
inpwsh
), then it stops working: PowerShell then somehow inherits the stdin and stdout, doesn't write anything to the PTY pipe and uses the stdout/stdin instead.For diagnostics, I've added output of
GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))
, which helps to detect if the output has been redirected (since it's not always obvious in practice). For pristine stdout, it should write2
, and other numbers for other output modes.How can I overcome this issue? Is it possible for my program to work even if its own stdout/stderr were redirected somewhere? I thought one of the points of PTY was to create a separate isolated environment, which won't interfere with the parent one.
Beta Was this translation helpful? Give feedback.
All reactions