microsoft / microsoft/terminal
End of output occasionally missing with `"closeOnExit": "never"`
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
### Windows Terminal version
1.23.10353.0
### Windows build number
10.0.22631.0
### Other Software
Build one of those (as is more convenient):
```csharp
using System;
public static class Program
{
public static void Main()
{
for (var i = 0; i <= 20_000; ++i)
Console.WriteLine($"LINE: {i}");
}
}
```
```cpp
#include
int main(int argc, char* argv[])
{
for (int i = 0; i <= 20000; ++i)
std::cout << "LINE: " << i << std::endl;
return 0;
}
```
```rust
fn main() {
for i in 0..=20_000 {
println!("LINE: {i}");
}
}
```
### Steps to reproduce
- In your default profile settings, set *Advanced* -> *Profile termination behavior* to *"Never close automatically"*
JSON equivalent:
```json
"profiles": {
"defaults": {
"closeOnExit": "never"
```
- Build one of the source codes provided above
- Double-click on the compiled exe file (do *not* run it from a shell)
### Expected Behavior
The output should *always* end with the following lines:
```
LINE: 19995
LINE: 19996
LINE: 19997
LINE: 19998
LINE: 19999
LINE: 20000
[process exited with code 0 (0x00000000)]
You can now close this terminal with Ctrl+D, or press Enter to restart.
```
Restarting the process by pressing Enter any number of times should not change this outcome.
### Actual Behavior
Most of the time, the behavior is as expected: the last line reads `LINE: 20000`.
However, after restarting the execution several times by pressing Enter, you can end up on an incomplete output, such as:

In the case of the C++ app, I even got the output cut in the middle of a line:

Getting this output may require 10 to 20 attempts, so please be patient. 😅
The problem is *not* reproducible when looping from a bat file:
```bat
@echo off
:loop
ConsoleApp.exe
pause
goto loop
```
However, a bat file which just runs the exe will reproduce the problem.
Contributor guide
Research direction
Start by reproducing the issue with closeOnExit set to never, launching the executable by double-clicking it and restarting with Enter; compare this with execution through a batch file. Trace the closeOnExit process-exit and output-handling path, then verify that repeated restarts always preserve the complete final line and exit message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100