Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file to determine if using Command Prompt

The last line in my batch file is pause. Is there any way to add a if condition to see if the script is run within command prompt or by double clicking to execute? I want to skip pause if it's running in command prompt.

...
...
if not RUN_IN_COMMAND_PROMPT (
  pause
)

EDIT: Hope to find a solution works in Windows Server 2003/2008, WinXP, Win7.

like image 232
Stan Avatar asked Jul 22 '11 21:07

Stan


2 Answers

CALL :GETMYSWITCH %CMDCMDLINE%
IF /I "%MYSWITCH%" == "/C" ECHO I WAS STARTED IN THE EXPLORER & PAUSE
IF /I NOT "%MYSWITCH%" == "/C" ECHO I WAS STARTED IN A DOS SESSION


:GETMYSWITCH
SET MYSWITCH=%2
like image 183
Aacini Avatar answered Sep 18 '22 01:09

Aacini


I know this is a year later but for future people searching you can use

If /I "%COMSPEC%" == %CMDCMDLINE% Goto SkipPause
pause
:SkipPause

It will skip the pause block if running from the command line and pause if running from batch file.

like image 38
Bja Avatar answered Sep 19 '22 01:09

Bja