Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#1
Post
by Ed Dyreen » 06 Dec 2011 22:22
Code: Select all
@echo off &setlocal disableDelayedExpansion
:: (
set ^"@Delayed=( set "$NotDelayedFlag=!" ^&if defined $NotDelayedFlag ( echo.result : NotDelayed ) else echo.result : Delayed )"
%@Delayed% &echo.correct: NotDelayed
setlocal enableDelayedExpansion
:: (
%@Delayed% &echo.correct: Delayed
echo.
for /f "usebackq tokens=*" %%1 in ( `cmd /v:on /e:on /t:0B /q /c "!@Delayed!"` ) do echo.%%1
echo.correct: Delayed
for /f "usebackq tokens=*" %%1 in ( `cmd /v:off /e:on /t:0B /q /c "!@Delayed!"`) do echo.%%1
echo.correct: NotDelayed
:: )
endlocal
:: )
endlocal
pause
exit
Code: Select all
result : NotDelayed
correct: NotDelayed
result : Delayed
correct: Delayed
result : NotDelayed
correct: Delayed
result : NotDelayed
correct: NotDelayed
Druk op een toets om door te gaan. . .
What the hell

-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#2
Post
by dbenham » 06 Dec 2011 23:51
Ed - The IN() clause command is run within its own CMD context outside of the batch context. The parsing rules are different
Non-existent or ill-formed delayed expansion expressions are stripped out in a batch context, but they are left alone in a command line context. So the test can't work within a command in an IN() clause.
The above info is buried in
http://stackoverflow.com/a/4095133/1012053Dave Benham
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#3
Post
by Ed Dyreen » 07 Dec 2011 01:02
'
Thanks, that helps
alot, I'm experimenting with running macro's in their own CMD session, and then interpreting the output that they print on
con with
for. To break macro's and have them interpreted by a
"main" macro.
I first convert the linefeeds using a technique jeb explained to me
viewtopic.php?f=3&t=1827&start=60Code: Select all
%cmdMacro_% @macro %= converts macro's to macro's that can be run through cmd =%
::
for /f "usebackq tokens=*" %%1 in ( `cmd /V:on /E:on /T:0B /q /c "!@macrocmd!"` ) do (
::
echo.%%1
)