-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terminal window/tab is not closed when console application calls FreeConsole #14416
Comments
I've looked at other similar issues on this repository, but all of them are related to the program manually working on the console window HANDLE that as said various times was a deprecated behaviour, for |
We could make this work by removing ConPTY's BTW if you're using // Compile with /SUBSYSTEM:WINDOWS!
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
AllocConsole();
}
FILE* stdinNew = nullptr;
freopen_s(&stdinNew, "CONIN$", "r+", stdin);
FILE* stdoutNew = nullptr;
freopen_s(&stdoutNew, "CONOUT$", "w+", stdout);
FILE* stderrNew = nullptr;
freopen_s(&stderrNew, "CONOUT$", "w+", stderr);
printf("Hello, World!\n"); |
Yes, I'm doing that but because before my program reads its configs from which the console can be disabled, it has already printed some debug information that would not be there if I created the console afterwards (this is where I'm doing that call, by that time the console has already debug Info from its libraries printed to the console https://github.com/edo9300/edopro/blob/bce9989dbf6f497d1b5f3c009f4b6328d80e9201/gframe/gframe.cpp#L223), so I can't create the console afterwards. |
2 new ConPTY APIs were added as part of this commit: * `ClosePseudoConsoleTimeout` Complements `ClosePseudoConsole`, allowing users to override the `INFINITE` wait for OpenConsole to exit with any arbitrary timeout, including 0. * `ConptyReleasePseudoConsole` This releases the `\Reference` handle held by the `HPCON`. While it makes launching further PTY clients via `PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE` impossible, it does allow conhost/OpenConsole to exit naturally once all console clients have disconnected. This makes it unnecessary to having to monitor the exit of the spawned shell/application, just to then call `ClosePseudoConsole`, while carefully continuing to read from the output pipe. Instead users can now just read from the output pipe until it is closed, knowing for sure that no more data will come or clients connect. This is especially useful in combination with `ClosePseudoConsoleTimeout` and a timeout of 0, to allow conhost/OpenConsole to exit asynchronously. These new APIs are used to fix an array of bugs around Windows Terminal exiting either too early or too late. They also make usage of the ConPTY API simpler in most situations (when spawning a single application and waiting for it to exit). Depends on #13882, #14041, #14160, #14282 Closes #4564 Closes #14416 Closes MSFT-42244182 ## Validation Steps Performed * Calling `FreeConsole` in a handoff'd application closes the tab ✅ * Create a .bat file containing only `start /B cmd.exe`. If WT stable is the default terminal the tab closes instantly ✅ With these changes included the tab stays open with a cmd.exe prompt ✅ * New ConPTY tests ✅
🎉This issue was addressed in #14544, which has now been successfully released as Handy links: |
Windows Terminal version
No response
Windows build number
No response
Other Software
No response
Steps to reproduce
On windows 11, with the windows terminal being set as the default console application, start a program that was compiled for the console subsystem from explorer.
That program calls
FreeConsole
during its lifetime and then keeps running (either because it has spawned a gui or it is still has work to do).Expected Behavior
The console window that got spawned by that program is closed as it did with cmd on previous windows versions.
Actual Behavior
The console window stays open until the program terminates the execution.
The text was updated successfully, but these errors were encountered: