Blank parameter value

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
achowdh
Posts: 1
Joined: 26 Apr 2012 23:42

Blank parameter value

#1 Post by achowdh » 26 Apr 2012 23:54

I have a batch script where i am passing 6 parameters at command prompt while running the script. For example abc.bat -w www.test.com -i website_id -p httpport.........

Now i need to echo out message at command prompt if any input parameter is empty.

Now the problem i am facing while counting the parameters with %2,%4....is if any argument (www.test.com) is left blank the then the -w parameter is taking the next argument (-i website)
as its argument and i am not able to echo out the result for blank parameter value.

Kindly help ....

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Blank parameter value

#2 Post by Squashman » 27 Apr 2012 05:41

So just test if %6 is defined. If it isn't then goto a usage label and explain how the batch is run and then exit the batch file.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Blank parameter value

#3 Post by trebor68 » 27 Apr 2012 17:21

The batch "Test25.bat" will testet if there a option and have this option a parameter.

Here some examples:
Test25 /a television
Test25 /b /c world
Test25 /c "United kingdom" /a "United states"

Test25.bat

Code: Select all

@echo off
setlocal ENABLEEXTENSIONS
echo.
echo  Test25 [/a [par1]] ^| [/b [par2]] ^| [/c [par3]]
echo.
echo.  Use one or more options with or without a parameter.
echo   Parameter with more words you need double quotes.
echo.
set "arg1=" & set "arg2=" & set "arg3="
:nextpar
set "hlp="
for %%o in (/a /b /c) do if %1==%%o goto :%1
echo Error: unknow option
echo.
exit /b
::
:/a
if not %1#==# shift
for %%p in ('/b' '/c' '') do if '%1'==%%p set hlp=empty
if "%hlp%"=="empty" (set arg1=empty) else (set arg1=%1) & shift
if not %1#==# goto :nextpar
goto :prog
::
:/b
if not %1#==# shift
for %%p in ('/a' '/c' '') do if '%1'==%%p set hlp=empty
if "%hlp%"=="empty" (set arg2=empty) else (set arg2=%1) & shift
if not %1#==# goto :nextpar
goto :prog
::
:/c
if not %1#==# shift
for %%p in ('/a' '/b' '') do if '%1'==%%p set hlp=empty
if "%hlp%"=="empty" (set arg3=empty) else (set arg3=%1) & shift
if not %1#==# goto :nextpar
goto :prog
::
:prog
echo.
if defined arg1 echo Option '/a' with parameter '%arg1%'.
if defined arg2 echo Option '/b' with parameter '%arg2%'.
if defined arg3 echo Option '/c' with parameter '%arg3%'.
echo.

Post Reply