Skip to content
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 hangs on exit with 'process exited with code 127' message #4573

Closed
cristianciutea opened this issue Feb 13, 2020 · 20 comments
Closed
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@cristianciutea
Copy link

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.

Environment

Microsoft Windows [Version 10.0.18363.657]
Windows Terminal version: 0.9.433.0

Steps to reproduce

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]

Expected behavior

Windows Terminal tab should be closed.

Actual behavior

Windows Terminal tab freeze.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Feb 13, 2020
@DHowett-MSFT
Copy link
Contributor

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: #4223 (comment)

@DHowett-MSFT DHowett-MSFT added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Feb 13, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Feb 13, 2020
@carragom
Copy link

carragom commented Mar 20, 2020

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.

image

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

  1. Replace the message [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.
  2. Have a setting where I can bypass this behavior and close the pane/tab when the shell exits no matter the exit status of the last command. There already exists a 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.

@zadjii-msft
Copy link
Member

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.

@carragom
Copy link

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.

@zadjii-msft
Copy link
Member

@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
        ]
    }
}

@carragom
Copy link

Thanks a lot, when placing the closeOnExit on the specific profile it behaves as expected.

@weitzhandler
Copy link

weitzhandler commented May 11, 2020

By me, the closeOnExit setting was under defaults, though it was set to true. Changing it to "always" seems to do the job.

@jake-dev-99
Copy link

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.

@DHowett
Copy link
Member

DHowett commented May 18, 2020

@jaallen did you install powershell with scoop or dotnet global, or as a standard MSI?

@jake-dev-99
Copy link

@DHowett Was installed via standard MSI

@DHowett
Copy link
Member

DHowett commented May 18, 2020

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.

@jake-dev-99
Copy link

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.

@jake-dev-99
Copy link

@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.

@DHowett
Copy link
Member

DHowett commented May 18, 2020

@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)

@jake-dev-99
Copy link

@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

@AyoungDukie
Copy link

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.

@bilogic
Copy link

bilogic commented Sep 21, 2020

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.

@chinwobble
Copy link

Hi I'm getting this issue too in wsl ubuntu.

When I run a script and it fails it exits with

[process exited with code 1]

The entire shell terminates and I'd prefer to be able to press a hotkey to restart the shell in the same location.

@zadjii-msft
Copy link
Member

@chinwobble You're looking for something more like #4772

@eversonleal
Copy link

I added an alias called "exit" on my .bash_profile: alias exit="exit 0". It solved the problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests