Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

@Parse behavior

Recently I noticed some unexpected behavior with the Parse function. Not sure if this is WAD. It's definitely been the behavior since at least V25.

If I run this btm file three times (1) with a /d parameter, (2) with a /d 7 parameter, and (3) with no parameters

@echo off

echo.
echo CommandLine: %0 %*

echo.
echo --- Parse looking for Switch
echo Returned Value:%@Parse[".",/d,0]:

echo.
echo --- Parse looking for Argument following Switch
echo Returned Value:%@Parse[".",/d,1]:

echo.
echo --- Parse without asking for a return type (OR'd value)
echo Returned Value:%@Parse[".",/d]:
echo.
echo.
echo.



quit

I get the following results

CommandLine: c:\batfile\TestParse2.btm /d

--- Parse looking for Switch
Returned Value:/d:

--- Parse looking for Argument following Switch
Returned Value::

--- Parse without asking for a return type (OR'd value)
Returned Value:1:




CommandLine: c:\batfile\TestParse2.btm /d 7

--- Parse looking for Switch
Returned Value:/d:

--- Parse looking for Argument following Switch
Returned Value:7:

--- Parse without asking for a return type (OR'd value)
Returned Value:1:



CommandLine: c:\batfile\TestParse2.btm

--- Parse looking for Switch
Returned Value:0:

--- Parse looking for Argument following Switch
Returned Value:0:

--- Parse without asking for a return type (OR'd value)
Returned Value:0:

The first two runs gave me the expected results. But the third run (with no parameters) is returning a 0 when Parse is looking for the switch name or the argument following the switch. If there are no parameters on the command line I would have expected nothing to be returned for those two function calls.

Am I missing something?
 
WAD -- although the help could be a little clearer about this.

If you don't supply a command line to @PARSE, it falls through the routine and returns the default value 0. It would be better for you to check if the command line is empty before calling @PARSE.

It has always behaved this way; changing that at this point would constitute a breaking change and is unlikely to happen.
 
Back
Top