Batch files: Keep command window open if launched from windows, otherwise don’t

  • Question
    Anonymous
    Inactive

    If I run a batch file from windows (Start->Run, “mybatch.bat”), a window pops up, it executes, and then it closes. I’d like it to stick around in this usage.

    However, if running the same batch file from an existing terminal, I’d like it to use the current terminal, versus opening another one.

    Is this possible?

    That should be the normal behaviour. This batch:

    :: Q:\Test\2017\07\19\WhoStartedMe.cmd @Echo off Echo %cmdcmdline% pause 

    shows with what cmd line the batch was started and waits for any key
    Started win Win+R

    C:\WINDOWS\system32\cmd.exe /c ""Q:\Test\2017\07\19\WhoStartedMe.cmd" " Press any key to continue . . . 

    Started from an open cmd window:

    > WhoStartedMe.cmd "C:\WINDOWS\system32\cmd.exe" Press any key to continue . . . 

    Started from an open Powershell window:

    PS> .\WhoStartedMe.cmd C:\WINDOWS\system32\cmd.exe /c ""Q:\Test\2017\07\19\WhoStartedMe.cmd"" Press any key to continue . . . 

  • You must be logged in to reply to this topic.