Reputation: 29377
Is there a way to check that so I can put a conditional at the end not to close console window or wait for user key press but omit that if *.bat file was typed from the keyboard in another console and there is no need to do that because windows wont close at the end ?
Upvotes: 4
Views: 506
Reputation: 7130
You can use %CMDCMDLINE%
to check.
@echo off
CALL :GETMYSWITCH %CMDCMDLINE%
IF /I "%MYSWITCH%" == "/C" ECHO Used explorer & PAUSE
IF /I NOT "%MYSWITCH%" == "/C" ECHO used cmd
:GETMYSWITCH
SET MYSWITCH=%2
If it is the case that your batch file is being called from a script that you wrote rather than directly through a double-click, you can just have your script pass an argument to the batch file, then check for that to see if you need to pause
.
Updated my answer to use this 'function' that I got from here.
Upvotes: 3