[PR #14544] Add support for start /B and FreeConsole #30149

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

Original Pull Request: https://github.com/microsoft/terminal/pull/14544

State: closed
Merged: Yes


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
**Original Pull Request:** https://github.com/microsoft/terminal/pull/14544 **State:** closed **Merged:** Yes --- 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 ✅
claunia added the pull-request label 2026-01-31 09:38:56 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30149