Some undocumented things with turned off command extensions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Some undocumented things with turned off command extensions

#1 Post by npocmaka_ » 11 Feb 2017 06:16

these variables are not accessible - CMDCMDLINE , TIME , DATE , RANDOM , ERRORLEVEL , CMDEXTVERSION , CD (but __CD__ is still there)


COLOR command is not working.
Last edited by npocmaka_ on 11 Feb 2017 09:42, edited 1 time in total.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Some undocumented things with turned of command extensions

#2 Post by penpen » 11 Feb 2017 07:07

The following is not undocumented - but the documentation is just wrong (at least the german version).

The setlocal always accepts the command line arguments (even if extensions are disabled):
- "enableExtensions" and
- "enableDelayedExpansion".


penpen

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Some undocumented things with turned of command extensions

#3 Post by aGerman » 11 Feb 2017 07:11

It's interesting that the color command doesn't work :?

As to the dynamic variables - actually it's documented behavior. Have a look at the help message of SET. The explanation of these variables begins with "If Command Extensions are enabled ...".
http://www.dostips.com/DosCommandIndex.php#SET

Steffen

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Some undocumented things with turned of command extensions

#4 Post by npocmaka_ » 11 Feb 2017 09:47

aGerman wrote:As to the dynamic variables - actually it's documented behavior. Have a look at the help message of SET. The explanation of these variables begins with "If Command Extensions are enabled ...".
http://www.dostips.com/DosCommandIndex.php#SET

Steffen


I should read the documentation more carefully.
Though for the color I've found nothing.

mcnd
Posts: 27
Joined: 08 Jan 2014 07:29

Re: Some undocumented things with turned off command extensions

#5 Post by mcnd » 11 Feb 2017 11:30

COLOR, ASSOC and FTYPE are associated to command extensions but are not documented as dependent on them.

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Some undocumented things with turned off command extensions

#6 Post by npocmaka_ » 11 Feb 2017 14:25

mcnd wrote:COLOR, ASSOC and FTYPE are associated to command extensions but are not documented as dependent on them.

So assoc and ftype will not work also?

EDIT
Just tried. They are not working. Thanks for the info.

Sponge Belly
Posts: 216
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: Some undocumented things with turned off command extensions

#7 Post by Sponge Belly » 12 Feb 2017 11:18

Hello All! :)

Interesting discussion. I’d like to add the following observations made while extensions were disabled.

The PROMPT command doesn’t work. Neither does:

Code: Select all

set "prompt=@"


Otoh…

Code: Select all

set prompt=@


does work. :?

And another thing I’ve noticed is that if there are 2 labels with the same name, GOTO will jump to the 2nd label. Yet another example of CMD’s eccentric behaviour.

BFN!

- SB

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Some undocumented things with turned off command extensions

#8 Post by jeb » 12 Feb 2017 12:50

Code: Select all

set "prompt=something"

Fails as the extended SET-syntax is no longer valid in the disbaled extension context.

I can't reproduce your goto :label problem.
I can't believe it, as any goto normally starts a search from the current file position to the first matching label.

Code: Select all

@echo off
setlocal DisableExtensions

goto :myLabel

:myLabel
echo First
goto :eof

:myLabel
echo Second
goto :eof

:eof


This outputs, as expected, "First".

Btw. You need to define the :eof label, as it doesn't exists without extensions.
Curious is the error message of "exit /b" in this context.
Free translation from german wrote:The label - :EOF can't be found

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Some undocumented things with turned off command extensions

#9 Post by npocmaka_ » 12 Feb 2017 14:20

jeb wrote:
Btw. You need to define the :eof label, as it doesn't exists without extensions.
Curious is the error message of "exit /b" in this context.
Free translation from german wrote:The label - :EOF can't be found


So exit uses goto to find the end of the file?

Should this mean that goto :eof works faster than exit /b ?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Some undocumented things with turned off command extensions

#10 Post by aGerman » 12 Feb 2017 14:30

npocmaka_ wrote:Should this mean that goto :eof works faster than exit /b ?

Most likely. Since you can pass a return value to exit /b the cmd has to evaluate a potential 3rd argument.

Steffen

Sponge Belly
Posts: 216
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: Some undocumented things with turned off command extensions

#11 Post by Sponge Belly » 12 Feb 2017 15:23

Hi Again! :)

I noticed the GOTO glitch when playing around with the code developed in the Foolproof Counting of Arguments topic. I’ve boiled it down to this:

Code: Select all

@echo off & setlocal enableextensions disabledelayedexpansion

(
goto skip
:skip
echo(first label
)

:skip
echo(second label

endlocal & goto :eof


The first ECHO statement is skipped, but change the second label name and both ECHO statements will be executed! :o

Btw, I had to revise this post with simpler code… twice! I now realise this phenomenon has nothing to do with disabled extensions. :oops:

- SB
Last edited by Sponge Belly on 14 Feb 2017 12:58, edited 1 time in total.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Some undocumented things with turned off command extensions

#12 Post by penpen » 12 Feb 2017 17:22

Sponge Belly wrote:The ampersand (&) can’t be used as command separator when extensions are disabled.
What do you mean, by saying the above?
The following should work as always: "&", "&&", "|", "||".


The command line interpreter must read the complete "for"-loop before it is able to execute it.
Because of that the filepointer is in the line after the ")", and the next ":skip" label is the second in the batch.

If you change the second label, then the cli will find the only ":skip"-label in this batch, because it is not in the same line as the ")" line.


penpen

Sponge Belly
Posts: 216
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: Some undocumented things with turned off command extensions

#13 Post by Sponge Belly » 14 Feb 2017 13:11

Hi Penpen,

Thanks for explaining GOTO’s mysterious behaviour. And you don’t need the body of a FOR loop or an IF block. An unconditional parenthesized block will do. See my previous post for a simplified code example.

And you’re right about the ampersand as command separator. I don’t know what I was thinking. I've removed the erroneous postscript from my previous post. :oops:

Finally, GOTO :EOF will work with extensions disabled, but :EOF must be in capitals.

- SB

CJM
Posts: 19
Joined: 25 Oct 2019 20:34
Location: Baltimore, MD USA

Re: Some undocumented things with turned off command extensions

#14 Post by CJM » 21 Jun 2021 07:44

Sponge Belly wrote:
14 Feb 2017 13:11
GOTO :EOF will work with extensions disabled, but :EOF must be in capitals.
I cannot get GOTO :EOF (nor GOTO:EOF, with or without space, in all-caps) to function with DisableExtensions unless an :EOF (or :eof) label is present.

I tested:
- on both Windows 2000 [5.00.2195] and Windows 10 [10.0.19042.1052]
- using a Command Prompt started with CMD /E:OFF and/or with SETLOCAL DISABLEEXTENSIONS in the batch files
- using .BAT and .CMD extensions

With no :EOF label present, lower case GOTO:eof fails fatally:

Code: Select all

>type EOFlower.bat
@IF ~0==%~0 ECHO/Extensions: Disabled
GOTO:eof
ECHO/Failed: GOTO:eof

>EOFlower.bat
Extensions: Disabled

>GOTO:eof
The system cannot find the batch label specified - eof
With no :EOF label present, upper case GOTO:EOF fails fatally:

Code: Select all

>type EOFupper.bat
@IF ~0==%~0 ECHO/Extensions: Disabled
GOTO:EOF
ECHO/Failed: GOTO:EOF

>EOFupper.bat
Extensions: Disabled

>GOTO:EOF
The system cannot find the batch label specified - EOF
Only this one worked (with :EOF present, case-insensitive):

Code: Select all

>type EOFin.bat
@IF ~0==%~0 ECHO/Extensions: Disabled
GOTO:EOF
ECHO/Failed: GOTO:EOF
:eof

>EOFin.bat
Extensions: Disabled

>GOTO:EOF

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Some undocumented things with turned off command extensions

#15 Post by jeb » 23 Jun 2021 12:08

Hi CJM,
CJM wrote:
21 Jun 2021 07:44
I cannot get GOTO :EOF (nor GOTO:EOF, with or without space, in all-caps) to function with DisableExtensions unless an :EOF (or :eof) label is present.
It's the expected behavior. With Disabled Extensions there is no implicit :EOF label anymore.

I'm not sure what Sponge Belly said with, if he said anything about adding a label or not
Sponge Belly wrote:
14 Feb 2017 13:11
Finally, GOTO :EOF will work with extensions disabled, but :EOF must be in capitals.
jeb

Post Reply