Repository navigation
Description
Windows Terminal version
1.12.10983.0
Windows build number
10.0.22000.0
Other Software
No response
Steps to reproduce
- In Terminal settings I have Default profiler=powershell, Launch mode=Open windows from a previous session
- Create two .bat files in a folder on my desktop:
a.bat:
echo %cd%
echo This is A
set /p someTestVariable="Press a key"
b.bat:
echo %cd%
echo This is B
set /p someTestVariable="Press a key"
- double-click on a.bat so it's launched in Terminal. Close the window.
- double-click on b.bat. Notice that both a.bat and b.bat have been run!
a.bat has been opened with working directory as my home directory. b.bat has been opened with working directory as the directory containing the .bat file.
Expected Behavior
Only the .bat file I double-clicked on should run
Actual Behavior
Maybe this is expected behaviour but I find it quite weird: when I launch a .bat file in Terminal it also opens up another window and runs whichever .bat file I ran last. If that's the same as the one I'm opening now then two instances of it are opened.
I don't think .bat files should be auto-launched even if "Open windows from a previous session" is selected. Surely this setting is for how many tabs you have open, current directory, etc, not for re-running .bat files that can have serious consequences?
At the least if you're opening the same .bat file as last time then only a single instance should be opened, not two.
Activity
zadjii-msft commentedon Jun 13, 2022
Yea, this is the expected behavior. It's basically like running
MicrosoftEdge.exe github.comafter closing a single edge window - you're gonna get both the previous window and a new tab for github.Now, maybe we should be more clever for defterm instances like this. Like, should we really persist a tab that was running a
batfile like that? That seems... mildly unexpected. But then for something like "runpwsh.exe, close it, openfoo.bat", that makes sense to bring thepwshTerminal window back - that was the last thing you had running.Yea, I'm gonna say this is by design. Sorry if it's a little unexpected! IIRC, closing the tab with the X button on the tab itself will prevent it from being persisted for the next launch. That we interpret as "the user wanted to close this thing and not see it again", vs closing the window as "close the terminal, but bring everything back".
rjk commentedon Jun 15, 2022
Ok, I can understand if it's "by design" but I'll put in a suggestion to change that designed behavior.
There's a significant difference between this reopening browser tabs. Reopening tabs doesn't typically cause destructive actions, e.g. if your last action on github was "confirm delete all my repositories" and you reopened your browser some weeks later you'd be quite surprised if github deleted all the new repositories you'd created in those weeks. For example, the browser will probably only make GET requests, not POST requests even if that was the last action in a tab before closing.
I think there's a big difference between which tabs you had running, what their current directories are, and things like .bat files, since .bat files can be destructive. This means "Open windows from a previous session" becomes VERY dangerous. Normal users who don't think about such things could go for months happily using Terminal with that setting, then one day run a .bat file that does , and then not understand why it's automatically run the next time they start Terminal.
At the least there should be a warning about persisted commands from previous sessions that could be destructive.
Anyways, I'll open a new issue for that discussion.