Hi!
I've noticed that on newer releases(starting from 0.8.x) when you try to close the terminal(with exit command or ctrl+d) after executing a command that returned an error status code, the tab hangs with the message:
[process exited with code
This happens on wsl and cmd.
Microsoft Windows [Version 10.0.18363.657]
Windows Terminal version: 0.9.433.0
Execute from cmd a command that produce an error then try to close with exit command: e.g:
C:\Users\cristi>asd
'asd' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\cristi>exit
[process exited with code 9009]
Same behavior in WSL when exit or ctrl+d:
/mnt/c/Users/cristi$ false
/mnt/c/Users/cristi$ exit
[process exited with code 1]
Windows Terminal tab should be closed.
Windows Terminal tab freeze.
Hey there! This is, unfortunately, by design; it's highly conserved across different types of shells (bash, zsh, powershell and CMD all do the same thing) and the behavior of not closing the tab is in line with Ubuntu's terminal: https://github.com/microsoft/terminal/issues/4223#issuecomment-574834181
Hi,
I agree that not closing the tab/pane on error is correct. But one question remains, how do I close a split pane after it got to that dead state? See screenshot.

When a terminal only support tabs, as it was before splits landed, this is not too problematic because I can open a new tab and close the dead one (not ideal but acceptable). But now that splits are supported, closing a tab might mean loosing work since a tab might contain more than one terminal. There seem to be an action to close a pane here but this should have better default behavior.
My proposal for this would be
[process exited with code 1] with something like [process exited with code 1, press <key> to exit]. Where key could be enter, space or another sensible key. And of course implement the functionality of closing the pane/tab when the key is pressed. closeOnExit option but I have it on always and the pane/tab does not close.On other related comments like this one the default behavior of never closing is suppose to exist to prevent a terminal from closing on startup because of a miss configuration on the shell. This behavior should never be lost even if proposal number 2 gets implemented.
I know I could place something like this inside my ~/.bash_logout to achieve what I want but that is just bad UX and specific to bash. This should be handled in the terminal and work with any shell.
if [ "$SHLVL" = 1 ]; then
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
exit 0
If there already exist a way to achieve any of my proposals please point me on the right direction.
Thanks.
Hey so for the record, we already have a key bound to "close pane" by default, and have for some time now :) Ctrl+Shift+W, which is the default keybinding for closePane will try to close the active pane, and if there's only one pane in the tab, it'll just close the tab. So if you've been using that to close tabs, it'll _just work_ for closing panes as well.
/cc @DHowett-MSFT, because "closeOnExit":"always" _should_ work the way you want.
Thanks for the quick response, Ctrl+Shift+W does close the dead pane/tab but I still think press <key> to exit would be a better feature.
As for "closeOnExit": "always" I'm not sure why it does not work for me, I do have it in the global section and not on any specific profile.
@carragom Oh, that explains it - closeOnExit is a Profile setting. See this doc:
https://github.com/microsoft/terminal/blob/master/doc/cascadia/SettingsSchema.md#profiles
If you want it for all your profiles, you could try the following:
{
"profiles": {
"defaults": {
"closeOnExit": "always"
},
"list": [
// all your profiles go here
]
}
}
Thanks a lot, when placing the closeOnExit on the specific profile it behaves as expected.
By me, the closeOnExit setting was under defaults, though it was set to true. Changing it to "always" seems to do the job.
I'll add that this is happening under powershell when it's not expected, for example running a python script and hitting "Ctrl+C" to kill the script. When this happens it requires me to open a new terminal tab and re-navigate to my working directory.
@jaallen did you install powershell with scoop or dotnet global, or as a standard MSI?
@DHowett Was installed via standard MSI
Huh. That's unexpected. Usually we see "^C terminates everything, even things I didn't want it to" with the two powershell wrappers from scoop or dotnet global.
In that case, it's been a couple years since this machine was rebuilt, so it's possible I did some powershell gymnastics at some point that could have created this. Let me do some deep-diving and I'll report back.
@DHowett Unfortunately I don't have much else to add. As far as I can tell, I'm just using the built-in powershell without any additional addons or modifications. When I ctrl+c from a hung python script, it prints code 3221225786 and closes the session on that tab. Let me know if I can provide anything specifically that might be of any help.
@jaallen _hmm_.
If this is PowerShell 7, can you run...
$p=(Get-Process -id $PID); ($p, $p.Parent) | ft Id,Path
(I hope you're on 7 :P)
@DHowett Unfortunately....I'm not lol
Running the above command, I get the following:
14856 C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
The $PSVersionTable shows me at 5.1.18362.752
Can confirm that this occurs for me when prematurely terminating a basic cmdlet with CTRL+C as well. I have installed from the Microsoft App Store in my case.
I like it that Terminal does not close if there was an error, this can be extremely helpful when you least expect it and I have always used a batch file shortcut x.bat which contains just @exit to exit and close cmd.exe.
I'm currently testing if @exit 0 solves this issue.
Most helpful comment
@carragom Oh, that explains it -
closeOnExitis a Profile setting. See this doc:https://github.com/microsoft/terminal/blob/master/doc/cascadia/SettingsSchema.md#profiles
If you want it for all your profiles, you could try the following: