Tabs opened through the command line automatically close when terminating their program #10551

Closed
opened 2026-01-31 02:24:28 +00:00 by claunia · 11 comments
Owner

Originally created by @Ariane-B on GitHub (Sep 8, 2020).

I'm using a long command-line shortcut to open several Windows Terminal tabs at the same time.

wt -p "Windows PowerShell" -d C:\Users\arianeb\backend --title backend-srv docker-compose up `; new-tab -p "Windows PowerShell" -d C:\Users\arianeb\frontend --title frontend-srv C:\Program Files\nodejs\npm.cmd run dev `; new-tab -p "Windows PowerShell" -d C:\Users\arianeb\backend --title backend `; new-tab -p "Windows PowerShell" -d C:\Users\arianeb\frontend --title frontend

It works fine, but afterwards, whenever I use Ctrl-C to stop/restart either of the servers that are launched in the first two tabs, the tab is closed, which is inconvenient.

It doesn't happen at all if I launch the server in a manually opened tab.

I'm sure it's something I didn't understand in the docs, an option somewhere that I missed. Can someone help me?

Originally created by @Ariane-B on GitHub (Sep 8, 2020). I'm using a long command-line shortcut to open several Windows Terminal tabs at the same time. ```powershell wt -p "Windows PowerShell" -d C:\Users\arianeb\backend --title backend-srv docker-compose up `; new-tab -p "Windows PowerShell" -d C:\Users\arianeb\frontend --title frontend-srv C:\Program Files\nodejs\npm.cmd run dev `; new-tab -p "Windows PowerShell" -d C:\Users\arianeb\backend --title backend `; new-tab -p "Windows PowerShell" -d C:\Users\arianeb\frontend --title frontend ``` It works fine, but afterwards, whenever I use Ctrl-C to stop/restart either of the servers that are launched in the first two tabs, the tab is closed, which is inconvenient. It doesn't happen at all if I launch the server in a manually opened tab. I'm sure it's something I didn't understand in the docs, an option somewhere that I missed. Can someone help me?
claunia added the Resolution-Duplicate label 2026-01-31 02:24:28 +00:00
Author
Owner

@DHowett commented on GitHub (Sep 8, 2020):

Have you changed closeOnExit to always?

The three accepted values for closeOnExit are the following:

  • always: if the application terminates for any reason, close the tab
  • graceful: if the application terminates with no error, close the tab
  • never: if the application terminates for any reason, keep the tab open.
@DHowett commented on GitHub (Sep 8, 2020): Have you changed `closeOnExit` to `always`? The three accepted values for `closeOnExit` are the following: * `always`: if the application terminates for any reason, close the tab * `graceful`: if the application terminates **with no error**, close the tab * `never`: if the application terminates for any reason, keep the tab open.
Author
Owner

@Ariane-B commented on GitHub (Sep 8, 2020):

closeOnExit isn't in my Settings.json, so I can only assume it's at its default value, "graceful".

@Ariane-B commented on GitHub (Sep 8, 2020): `closeOnExit` isn't in my Settings.json, so I can only assume it's at its default value, `"graceful"`.
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

Ah, I see. It looks like you might be interested in /dup #4772. Exiting an application with Ctrl+C looks like a successful exit, but I bet the thing you want is to relaunch them 😄

@DHowett commented on GitHub (Sep 10, 2020): Ah, I see. It looks like you might be interested in /dup #4772. Exiting an application with <kbd>Ctrl+C</kbd> looks like a successful exit, but I bet the thing you want is to relaunch them :smile:
Author
Owner

@ghost commented on GitHub (Sep 10, 2020):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Sep 10, 2020): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Author
Owner

@Ariane-B commented on GitHub (Sep 10, 2020):

What I don't understand is why manually opened tabs don't get closed when I end a process with Ctrl-C, while they do if they were opened with the wt command.

@Ariane-B commented on GitHub (Sep 10, 2020): What I don't understand is why manually opened tabs don't get closed when I end a process with Ctrl-C, while they do if they were opened with the `wt` command.
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

When you manually open a tab, is it a tab directly to "docker-compose" or is it running powershell or cmd?

If it's running powershell or cmd, and then you run docker-compose (or npm, or anything else)... the Ctrl+C is returning you to the shell.

When you run wt docker-compose (or npm, ...) there is no other shell running!

If you want that behavior, you will need to explicitly request it. Terminal doesn't want you to pay for something you are not using, like an extra shell process.

As an example,

wt cmd /k docker-compose up

if you press ^C in that tab, cmd will come back because it was asked to "keep running" (/k)

For powershell, it is a little different:

wt powershell -noexit -command docker-compose up

Does that help?

@DHowett commented on GitHub (Sep 10, 2020): When you manually open a tab, is it a tab directly to "docker-compose" or is it running powershell or cmd? If it's running powershell or cmd, and _then_ you run docker-compose (or npm, or anything else)... the <kbd>Ctrl+C</kbd> is _returning you to the shell_. When you run `wt docker-compose` (or npm, ...) there is no other shell running! If you want that behavior, you will need to explicitly request it. Terminal doesn't want you to pay for something you are not using, like an extra shell process. As an example, ``` wt cmd /k docker-compose up ``` if you press ^C in that tab, _cmd will come back_ because it was asked to "keep running" (`/k`) For powershell, it is a little different: ``` wt powershell -noexit -command docker-compose up ``` Does that help?
Author
Owner

@Ariane-B commented on GitHub (Sep 10, 2020):

I see... thanks for the explanation. I don't think I could've found that info by myself.

I wasn't aware it was possible for a CLI program to run without executing a shell. I was just assuming that if I picked the PowerShell profile, it was executing PowerShell. That's wild. (And it kinda feels like grasping at droplets of performance to me, considering how light a program a shell is, but never mind that.)

In your example programs, what are cmd and powershell ? Are they the final "execute this command upon tab open" argument? So they'd go after any profile, tab name, etc. arguments?

@Ariane-B commented on GitHub (Sep 10, 2020): I see... thanks for the explanation. I don't think I could've found that info by myself. I wasn't aware it was possible for a CLI program to run without executing a shell. I was just assuming that if I picked the PowerShell profile, it was executing PowerShell. That's wild. (And it kinda feels like grasping at droplets of performance to me, considering how light a program a shell is, but never mind that.) In your example programs, what are `cmd` and `powershell` ? Are they the final "execute this command upon tab open" argument? So they'd go after any profile, tab name, etc. arguments?
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

cmd and powershell are the actual shells! They're the ones that launch when you choose "Command Prompt" and "Windows PowerShell" from your profile list.

When we run them like this, we're saying "windows terminal, please start powershell" and "powershell, please start docker-compose".

Another reason that Terminal will not automatically run a shell is that it can't know which one you want! Running "wt docker-compose" is actually just like finding docker-compose.exe and double-clicking on it. In Windows, it's normal to run a commandline application without a shell. That's just how they launch if you run them from a shortcut, or from your desktop, or even by using the Run dialog!

@DHowett commented on GitHub (Sep 10, 2020): `cmd` and `powershell` are the actual shells! They're the ones that launch when you choose "Command Prompt" and "Windows PowerShell" from your profile list. When we run them like this, we're saying "windows terminal, please start powershell" and "powershell, please start `docker-compose`". Another reason that Terminal will not automatically run a shell is that it can't know which one you want! Running "wt docker-compose" is actually just like finding `docker-compose.exe` and double-clicking on it. In Windows, it's normal to run a commandline application without a shell. That's just how they launch if you run them from a shortcut, or from your desktop, or even by using the Run dialog!
Author
Owner

@Ariane-B commented on GitHub (Sep 10, 2020):

That's interesting info. It'll take a while before I wrap my head around the concept of "CLI, but like, not in a shell", but I'll get there, lol.

But isn't it loading the profile I asked it to run? Like, doesn't wt -p "Windows PowerShell" mean "run Terminal, and open a PowerShell tab"? That's the thing I was confused about. I really thought profiles running shells was implicit.

@Ariane-B commented on GitHub (Sep 10, 2020): That's interesting info. It'll take a while before I wrap my head around the concept of "CLI, but like, not in a shell", but I'll get there, lol. But isn't it loading the profile I asked it to run? Like, doesn't `wt -p "Windows PowerShell"` mean "run Terminal, and open a PowerShell tab"? That's the thing I was confused about. I really thought profiles running shells was implicit.
Author
Owner

@Ariane-B commented on GitHub (Sep 10, 2020):

Also, I'm realizing I've been sounding a tad dickish throughout this whole interaction. I apologize, and I wanted you to know your kind explanations were very much appreciated. Thanks.

@Ariane-B commented on GitHub (Sep 10, 2020): Also, I'm realizing I've been sounding a tad dickish throughout this whole interaction. I apologize, and I wanted you to know your kind explanations were very much appreciated. Thanks.
Author
Owner

@floriensk commented on GitHub (Jun 27, 2022):

I wonder if there is a similar solution if I want to invoke the command with WSL instead of PowerShell, like so:
wt new-tab -p "WSL (Ubuntu)" wsl echo "hallo"

@floriensk commented on GitHub (Jun 27, 2022): I wonder if there is a similar solution if I want to invoke the command with WSL instead of PowerShell, like so: `wt new-tab -p "WSL (Ubuntu)" wsl echo "hallo"`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#10551