Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Batch interpreter parses command line in slightly different manner than pure command line parser (read answers to another question at StackOverflowanswers to another question at StackOverflow):

  • command line: to avoid expanding %MYAPPSDIR% by command line interpreter, the % percent character should be escaped by the standard CLI escape character (^ caret): ^%MYAPPSDIR^% or ^%1;
  • .bat script: to avoid expanding %MYAPPSDIR% or %1 by batch interpreter, the % percent character should be doubled as follows: %%MYAPPSDIR%% and %%1, respectively.

To distinguish parameters supplied to your batch script:

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:.exe=%"
)
if "%par%"=="%par1%" (
  echo .exe not present
) else (
  echo .exe present
)

or (maybe better)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:~-4%"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

or (maybe the best)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%~x1"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

Resources (required reading):

Batch interpreter parses command line in slightly different manner than pure command line parser (read answers to another question at StackOverflow):

  • command line: to avoid expanding %MYAPPSDIR% by command line interpreter, the % percent character should be escaped by the standard CLI escape character (^ caret): ^%MYAPPSDIR^% or ^%1;
  • .bat script: to avoid expanding %MYAPPSDIR% or %1 by batch interpreter, the % percent character should be doubled as follows: %%MYAPPSDIR%% and %%1, respectively.

To distinguish parameters supplied to your batch script:

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:.exe=%"
)
if "%par%"=="%par1%" (
  echo .exe not present
) else (
  echo .exe present
)

or (maybe better)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:~-4%"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

or (maybe the best)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%~x1"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

Resources (required reading):

Batch interpreter parses command line in slightly different manner than pure command line parser (read answers to another question at StackOverflow):

  • command line: to avoid expanding %MYAPPSDIR% by command line interpreter, the % percent character should be escaped by the standard CLI escape character (^ caret): ^%MYAPPSDIR^% or ^%1;
  • .bat script: to avoid expanding %MYAPPSDIR% or %1 by batch interpreter, the % percent character should be doubled as follows: %%MYAPPSDIR%% and %%1, respectively.

To distinguish parameters supplied to your batch script:

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:.exe=%"
)
if "%par%"=="%par1%" (
  echo .exe not present
) else (
  echo .exe present
)

or (maybe better)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:~-4%"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

or (maybe the best)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%~x1"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

Resources (required reading):

added 1428 characters in body
Source Link
JosefZ
  • 13.4k
  • 5
  • 40
  • 72

Batch interpreter parses command line in slightly different manner than pure command line parser (read answers to another question at StackOverflow):

  • command line: to avoid expanding %MYAPPSDIR% by command line interpreter, the % percent character should be escaped by the standard CLI escape character (^ caret): ^%MYAPPSDIR^% or ^%1;
  • .bat script: to avoid expanding %MYAPPSDIR% or %1 by batch interpreter, the % percent character should be doubled as follows: %%MYAPPSDIR%% and %%1, respectively.

To distinguish parameters supplied to your batch script:

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:.exe=%"
)
if "%par%"=="%par1%" (
  echo .exe not present
) else (
  echo .exe present
)

or (maybe better)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:~-4%"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

or (maybe the best)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%~x1"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

Resources (required reading):

Batch interpreter parses command line in slightly different manner than pure command line parser (read answers to another question at StackOverflow):

  • command line: to avoid expanding %MYAPPSDIR% by command line interpreter, the % percent character should be escaped by the standard CLI escape character (^ caret): ^%MYAPPSDIR^% or ^%1;
  • .bat script: to avoid expanding %MYAPPSDIR% or %1 by batch interpreter, the % percent character should be doubled as follows: %%MYAPPSDIR%% and %%1, respectively.

Batch interpreter parses command line in slightly different manner than pure command line parser (read answers to another question at StackOverflow):

  • command line: to avoid expanding %MYAPPSDIR% by command line interpreter, the % percent character should be escaped by the standard CLI escape character (^ caret): ^%MYAPPSDIR^% or ^%1;
  • .bat script: to avoid expanding %MYAPPSDIR% or %1 by batch interpreter, the % percent character should be doubled as follows: %%MYAPPSDIR%% and %%1, respectively.

To distinguish parameters supplied to your batch script:

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:.exe=%"
)
if "%par%"=="%par1%" (
  echo .exe not present
) else (
  echo .exe present
)

or (maybe better)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%par1:~-4%"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

or (maybe the best)

set "par1=%~1"
if "%par1%"=="" (
  echo no parameter supplied
  goto :eof
) else (
  set "par=%~x1"
)
if /I "%par%"==".exe" (
  echo .exe present
) else (
  echo .exe not present
)

Resources (required reading):

Source Link
JosefZ
  • 13.4k
  • 5
  • 40
  • 72

Batch interpreter parses command line in slightly different manner than pure command line parser (read answers to another question at StackOverflow):

  • command line: to avoid expanding %MYAPPSDIR% by command line interpreter, the % percent character should be escaped by the standard CLI escape character (^ caret): ^%MYAPPSDIR^% or ^%1;
  • .bat script: to avoid expanding %MYAPPSDIR% or %1 by batch interpreter, the % percent character should be doubled as follows: %%MYAPPSDIR%% and %%1, respectively.