Skip to content

Opening a .bat file also executes whichever was the last .bat file I had open!? #13151

Closed as not planned

Description

@rjk

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

  1. added
    Issue-BugIt either shouldn't be doing this or needs an investigation.
    on May 24, 2022
  2. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on May 24, 2022
  3. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on May 24, 2022
  4. zadjii-msft commented on Jun 13, 2022

    @zadjii-msft
    Member

    Yea, this is the expected behavior. It's basically like running MicrosoftEdge.exe github.com after 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 bat file like that? That seems... mildly unexpected. But then for something like "run pwsh.exe, close it, open foo.bat", that makes sense to bring the pwsh Terminal 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".

  5. rjk commented on Jun 15, 2022

    @rjk
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsNeeds-TriageIt's a new issue that the core contributor team needs to triage at the next triage meetingProduct-TerminalThe new Windows Terminal.Resolution-By-DesignIt's supposed to be this way. Sometimes for compatibility reasons.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions