Page 1 of 1
Some undocumented things with turned off command extensions
Posted: 11 Feb 2017 06:16
by npocmaka_
these variables are not accessible - CMDCMDLINE , TIME , DATE , RANDOM , ERRORLEVEL , CMDEXTVERSION , CD (but __CD__ is still there)
COLOR command is not working.
Re: Some undocumented things with turned of command extensions
Posted: 11 Feb 2017 07:07
by penpen
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
Re: Some undocumented things with turned of command extensions
Posted: 11 Feb 2017 07:11
by aGerman
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#SETSteffen
Re: Some undocumented things with turned of command extensions
Posted: 11 Feb 2017 09:47
by npocmaka_
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#SETSteffen
I should read the documentation more carefully.
Though for the color I've found nothing.
Re: Some undocumented things with turned off command extensions
Posted: 11 Feb 2017 11:30
by mcnd
COLOR, ASSOC and FTYPE are associated to command extensions but are not documented as dependent on them.
Re: Some undocumented things with turned off command extensions
Posted: 11 Feb 2017 14:25
by npocmaka_
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?
EDITJust tried. They are not working. Thanks for the info.
Re: Some undocumented things with turned off command extensions
Posted: 12 Feb 2017 11:18
by Sponge Belly
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:
Otoh…
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
Re: Some undocumented things with turned off command extensions
Posted: 12 Feb 2017 12:50
by jeb
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
Re: Some undocumented things with turned off command extensions
Posted: 12 Feb 2017 14:20
by npocmaka_
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 ?
Re: Some undocumented things with turned off command extensions
Posted: 12 Feb 2017 14:30
by aGerman
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
Re: Some undocumented things with turned off command extensions
Posted: 12 Feb 2017 15:23
by Sponge Belly
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!
Btw, I had to revise this post with simpler code… twice! I now realise this phenomenon has nothing to do with disabled extensions.
- SB
Re: Some undocumented things with turned off command extensions
Posted: 12 Feb 2017 17:22
by penpen
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
Re: Some undocumented things with turned off command extensions
Posted: 14 Feb 2017 13:11
by Sponge Belly
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.
Finally, GOTO :EOF
will work with extensions disabled, but :EOF must be in capitals.
- SB
Re: Some undocumented things with turned off command extensions
Posted: 21 Jun 2021 07:44
by CJM
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
Re: Some undocumented things with turned off command extensions
Posted: 23 Jun 2021 12:08
by jeb
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