Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scrip quirks

2 views
Skip to first unread message

Timo Salmi

unread,
Mar 11, 2011, 1:29:23 AM3/11/11
to
Occasionally users report quirks of the cmd.exe batch script
interpreter. This must have been presented earlier, but I came upon it
accidentally while calling a working script.

In calling a script an quality (=) seems to be tantamount to a space.

For example
C:>MyScipt.cmd par1
C:>MyScipt.cmd=par1
behave the same way

Likewise
C:>MyScipt.cmd
is ok
C:>MyScipt.cmdNosuchFile
produces, as expected
"is not recognized as an internal or external command..."

but
C:>MyScipt.cmd/x
is ok (/x is taken as par1)

however, if one includes the path
C:>C:\wherever\MyScipt.cmd/x
one gets
The directory name is invalid.

All the best, Timo

--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.php

foxidrive

unread,
Mar 11, 2011, 1:37:50 AM3/11/11
to
On 11/03/2011 17:29, Timo Salmi wrote:
> Occasionally users report quirks of the cmd.exe batch script
> interpreter. This must have been presented earlier, but I came upon it
> accidentally while calling a working script.
>
> In calling a script an quality (=) seems to be tantamount to a space.

It's always been that way Timo, same as comma, semicolon, even back to
MSdos 3.3 where I came in.

@echo off
call :echo 1=2;3,4
call :echo "1=2;3,4"
pause
goto :EOF
:echo
echo %1-%2-%3-%4


--
Regards,
Mic

foxidrive

unread,
Mar 11, 2011, 1:48:57 AM3/11/11
to
On 11/03/2011 17:29, Timo Salmi wrote:

> however, if one includes the path
> C:>C:\wherever\MyScipt.cmd/x
> one gets
> The directory name is invalid.

My mistake, I didn't pay attention to what you were posting Timo.

The above seems to be a parsing issue where the /x is interpreted as \x


CMD.EXE does allow / or \ to be used in a path. See below.

D:\>type d:\myscript.cmd
@echo off
echo %1
pause


D:\>d:/myscript.cmd abc
abc
Press any key to continue . . .


D:\>d:\myscript.cmd abc
abc
Press any key to continue . . .


--
Regards,
Mic

jeb

unread,
Mar 11, 2011, 6:48:01 AM3/11/11
to
But it is a bit more complicated.

I have the files
c:\temp\test.bat
and
c:\temp\test\my.bat

both contains only
echo %0

Now I test
test
test/my.bat
..\temp\test/my.bat
c:\temp\test/my.bat

Only the last variant calls my.bat, all other calls test.bat with /
my.bat as parameter.
So only with absolute paths my.bat is taken as part of the filename.

And as foxidrive said:
Standard delims are "=,;" and "(" and also ALT-255, ALT-255 is not the
same as a normal space, as you can see with %*
test,param %*=",param" %1="param"
test;param %*=";param" %1="param"
test=param %*="=param" %1="param"
test(param %*="(param" %1="(param"
test<ALT-255>param %*=" param" %1="param"


On 11 Mrz., 07:48, foxidrive <foxidr...@gotcha.woohoo.invalid> wrote:
> On 11/03/2011 17:29, Timo Salmi wrote:
>
> > however, if one includes the path
> > C:>C:\wherever\MyScipt.cmd/x
> > one gets
> > The directory name is invalid.
>
> My mistake, I didn't pay attention to what you were posting Timo.
>
> The above seems to be a parsing issue where the /x is interpreted as \x
>
> CMD.EXE does allow / or \ to be used in a path.  See below.

> ...
> --
> Regards,
> Mic

Frank P. Westlake

unread,
Mar 11, 2011, 10:26:38 AM3/11/11
to
"Timo Salmi" news:4d79c142$0$2841$9188...@news.netikka.fi...

> C:>C:\wherever\MyScipt.cmd/x
> one gets
> The directory name is invalid.


This demonstrates that:

C:\>md C:\wherever\MyScipt.cmd

C:\>echo=echo=%~f0>C:\wherever\MyScipt.cmd\x.bat

C:\T>echo=C:\wherever\MyScipt.cmd\x.bat
C:\wherever\MyScipt.cmd\x.bat

Frank

Frank P. Westlake

unread,
Mar 11, 2011, 10:35:04 AM3/11/11
to
That was an erroneous copy and paste. This is more accurate:

C:\T>md C:\wherever\MyScipt.cmd

C:\T>echo=echo=%~f0>C:\wherever\MyScipt.cmd\x.bat

C:\T>C:\wherever\MyScipt.cmd\x.bat

C:\T>echo=C:\wherever\MyScipt.cmd\x.bat
C:\wherever\MyScipt.cmd\x.bat

For those wanting to try this here are the statements to copy and paste:

cd /d C:\
md C:\wherever\MyScipt.cmd


echo=echo=%~f0>C:\wherever\MyScipt.cmd\x.bat

C:\wherever\MyScipt.cmd\x.bat
rd /s /q C:\wherever

Frank


Todd Vargo

unread,
Mar 11, 2011, 9:08:25 PM3/11/11
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:4d79c142$0$2841$9188...@news.netikka.fi...

> Occasionally users report quirks of the cmd.exe batch script
> interpreter. This must have been presented earlier, but I came upon it
> accidentally while calling a working script.
>
> In calling a script an quality (=) seems to be tantamount to a space.
>
> For example
> C:>MyScipt.cmd par1
> C:>MyScipt.cmd=par1
> behave the same way
>
> Likewise
> C:>MyScipt.cmd
> is ok
> C:>MyScipt.cmdNosuchFile
> produces, as expected
> "is not recognized as an internal or external command..."
>
> but
> C:>MyScipt.cmd/x
> is ok (/x is taken as par1)
>
> however, if one includes the path
> C:>C:\wherever\MyScipt.cmd/x
> one gets
> The directory name is invalid.

Quirks of previous command interpreters should not be expected to behave the
same in latter versions.

0 new messages