☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vinden.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Ed Dyreen
Expert
Posts: 1527
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vinden.

#1 Post by Ed Dyreen » 18 Jun 2011 20:42

declare fit 3 tokens:

Code: Select all

set "@forç=for /f "usebackq tokens=1-26 delims= " %%a in"
execute split:

Code: Select all

%@forç% ( '$var, 0, 999' ) %@GetRandom%
result:

Code: Select all

 >> Pre Define @GetRandom
 $var : 205 [ok] Kan bestand ☺
♠☺??↨??$error =  7  niet vinden.

 << Post Define @GetRandom [OK]
for seems to have problems with comma separeted tokens and macros, they wont accept my input :?:

Why would the macro fail at the end ?, it just don't make sense !

My god, it look like it's shifting parameters :shock:

Code: Select all

for /f "usebackq tokens=1-26 delims= " %%a in ( '$var, 0, 999' ) %@GetRandom%
%@forç% ( '$var, 0, 999' ) %@GetRandom%
>> Pre Define @GetRandom
$var : 229 [ok]
'$var : 0 [ok]
0 : 0 [ok]
999' : 0 [ok]

<< Post Define @GetRandom [OK]

And it gets weirder:

Code: Select all

for /f "usebackq tokens=1-26 delims=' " %%a in ( '$var, 0, 999' ) %@GetRandom%
for /f "usebackq tokens=1-26 delims=' " %%a in ( '$var, 0, 999' ) %@GetRandom%
>> Pre Define @GetRandom
$var : 917 [ok]
$var : 253 [ok]
Kan bestand ☺?♥♠a♀???☻?☻ niet vinden.

<< Post Define @GetRandom [OK]
endoftest Druk op een toets om door te gaan. . . :shock:

Replace the comma and delims with ¦ and everything works :shock:

Code: Select all

%@Pre% @GetRandom
::
:: Retrieve a random number
::
::(
	set "$Defines=@GetRandom"
	::
	set ^"$Usage.%$Defines%=^
%	% Usage : %%@forA%% ( '"r#StoreVAR"¦"r?Mininmum"¦"r?Maximum"' ) %%%$Defines%%% %$n1c%
%	% input: %$n1c%
%	%  r#StoreVAR: name of return variable %$n1c%
%	%  r?Mininmum: Lower boundary %$n1c%
%	%  r?Maximum : Upper boundary %$n1c%
%	% ToConsole: %$n1c%
%	%  Contents of $StoreVAR %$n1c%
%	%  The output can be redirected. %$n1c%
%	% Return: %$n1c%
%	%  $error: 0 for succes, panic otherwise "
	::
	set ^"%$Defines%=do ( %$n1c%

		!@forTF! ( '"%$Defines%"¦"r#StoreVAR=%%~a"¦"r?Mininmum=%%~b"¦"r?Maximum=%%~c"' ) !@LeadIn! %$n1c%
		rem !@forTS! ( "@DebugIn" ) !@CallMacro! %$n1c%

		Setlocal EnableDelayedExpansion %$n1c%

		call set /a $StdOut = %%Random%% %%%% ^^^^^^^( $Maximum - $Minimum + 1 ^^^^^^^) + $Minimum %$n1c%

		!@forTS! ( %$n1c%

			"^!$StoreVAR^!=^!$StdOut^!" %$n1c%

		) 	!@PassOverEndlocal! %$n1c%

	) ^&( %$n1c%

		!@necho! %%~a : ^^^!%%~a^^^! [^^^!$0.error^^^!] %$n1c%

		rem !@forTS! ( "@DebugOut" ) !@CallMacro! %$n1c%
		!@LeadOut! %$n1c%
	)"
	::
	%@forç% ( '$var, 0, 999' ) %@GetRandom%
::)
%@Post% @GetRandom [OK]
:?: Is this a cmd bug ♠☺??↨??

I can simply supress the error, the macro is unaffected:

Code: Select all

( for /f "usebackq tokens=1-26 delims=' " %%a in ( '$var, 0, 999' ) %@GetRandom% ) 2>nul
( for /f "usebackq tokens=1-26 delims=' " %%a in ( '$var, 0, 999' ) %@GetRandom% ) 2>nul
( for /f "usebackq tokens=1-26 delims=' " %%a in ( '$var, 0, 999' ) %@GetRandom% ) 2>nul
>> Pre Define @GetRandom
$var : 26 [ok]
$var : 120 [ok]
$var : 510 [ok]

<< Post Define @GetRandom [OK]
endoftest Druk op een toets om door te gaan. . .

Any expert wants to tell me what's going on ?

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

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#2 Post by jeb » 20 Jun 2011 04:53

Hi Ed,

I see two of your standard problems here. :)

- First the sample is not small
- And the sample is not complete

Try to build a SMALL sample ( less than 500 lines, lets say 5 lines)

Try this today for a happy crash

Code: Select all

FOR %%A (1) DO (
  echo %%~
)


jeb

Ed Dyreen
Expert
Posts: 1527
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#3 Post by Ed Dyreen » 20 Jun 2011 07:30

small enough ?

Code: Select all

@echo off &setlocal enableextensions enabledelayedexpansion

for /f "usebackq tokens=1-26 delims=' " %%a in ( '$var, 0, 999' ) do echo.a=%%a b=%%b c=%%c

pause
exit /b
result:
a=$var b=0 c=999
♠k♀\ niet vinden.
Druk op een toets om door te gaan. . .

Code: Select all

@echo off &setlocal enableextensions enabledelayedexpansion

( for /f "usebackq tokens=1-26 delims=' " %%a in ( '$var, 0, 999' ) do echo.a=%%a b=%%b c=%%c ) 2>nul

pause
exit /b
result:
a=$var b=0 c=999
Druk op een toets om door te gaan. . . :shock:

I learnt most of this from u jeb, I thought the experts were familiar with the for comma problem v bug.
Last edited by Ed Dyreen on 20 Jun 2011 07:45, edited 1 time in total.

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

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#4 Post by jeb » 20 Jun 2011 07:45

Ed Dyreen wrote:Is this small enough for ya ?


Yes, this is small enough :)
But it works :?

Output wrote:a=$var b=0 c=999


Tested with Vista32.

jeb

Ed Dyreen
Expert
Posts: 1527
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#5 Post by Ed Dyreen » 20 Jun 2011 07:46

why doesn't it works on XP

I need this for an unattended installation batch, I can't fix something that has to be fixed . :cry:

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

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#6 Post by jeb » 20 Jun 2011 07:54

Hi Ed,

retested with XP32 (in a vm-box)

Yes, you are right :) , it fails ... sometimes
I build a loop

Code: Select all

@echo off 
setlocal

set count=1
:loop
for /f "usebackq tokens=1-26 delims=' " %%a in ( '$var, 0, 999' ) do echo.a=%%a b=%%b c=%%c

set /a count+=1
if %count% leq 50 goto :loop


Now it fails one or two times out of 50.
But the cause seems to be the ' character.

If I change it to " and remove the usebackq it works always

Code: Select all

@echo off 
setlocal

set count=1
:loop
for /f "tokens=1-26 delims=," %%a in ( "$var,0,999" ) do echo( %count% a=%%a b=%%b c=%%c

set /a count+=1
if %count% leq 50 goto :loop


jeb

Ed Dyreen
Expert
Posts: 1527
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#7 Post by Ed Dyreen » 20 Jun 2011 08:02

jeb to the resque :D

Code: Select all

@echo off &setlocal enabledelayedexpansion

for /f "tokens=1-26 delims=, " %%a in ( "$var, 0, 999" ) do echo.a=%%a_ b=%%b_ c=%%c_

pause
exit /b
result:
a=$var_ b=0_ c=999_
Druk op een toets om door te gaan. . . :mrgreen:

I assume my assumption that this must be a cmd v2 bug is correct ?
Then I wonder if I could replace XP's cmd with vista's cmd ?
It's a good thing the comma vanishes, but why ?

And did you notice ?

Code: Select all

%@forç% ( '$var, 0, 999' ) %@GetRandom%
@GetRandom is executed 3 times !
'$var : 0 [ok]
0 : 0 [ok]
999' : 0 [ok]

and %%a is shifting once for every execution !
I wonder if this effect can be turned to our advantage..

Now I can finally use AutoIT style functions :D
%@forTF% ( '@forç, @Testforçmacro, $This, "$Works", "This Works"' ) %@CallMacro%
Last edited by Ed Dyreen on 20 Jun 2011 16:06, edited 1 time in total.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#8 Post by orange_batch » 20 Jun 2011 12:57

viewtopic.php?f=3&t=1970&p=8581&hilit=usebackq#p8581

I only recommend using usebackq if you're reading text from a file with a path that contains spaces, or special characters. Quotation marks toggle the command interpreter's processing of special characters irregardless of where you do it, so it's good to have them for string processing too.
8)

Ed Dyreen
Expert
Posts: 1527
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#9 Post by Ed Dyreen » 20 Jun 2011 20:36

I had to do quite an effort to get it working the way I wanted on XP:

Code: Select all

set "@forU=set "?=" &( for %%^^^! in"

set "@Udelim=do set "?=^^^!?^^^!¦%%^^^!" ) &set "?=^^^!?:*¦=^^^!" &set "?=^^^!?:~1,-1^^^!" &for /f "tokens=1-26 delims=¦" %%a in ( "^^^!?^^^!" ) do"
::
%@forU% ( '$Debug, "This Works"' ) %@Udelim% echo. a=%%a_ &echo. b=%%b_

set ^"@PushArray=!@Udelim! ( %$n1c%
   echo. a=%%a_ %$n1c%
   echo. b=%%b_ %$n1c%
)"
::
%@forU% ( '$Debug, "This Works"' ) %@PushArray%
I can't use the double quotes solution jeb, this would mess up the internal double quotes.
Finally, I've got what I wanted.
8)

Ed Dyreen
Expert
Posts: 1527
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#10 Post by Ed Dyreen » 04 Jul 2011 04:49

I can't give the full code to prove my statement, as it is too much and too complex.

Unlike most people I only have one function, it's a function that pasts macro's together so I can get past the 8k limit. It looks something like:

Code: Select all

(
	Endlocal

	%$for% ( %$param% ) %$macro%
)
Unlike with jeb the for either always fails or it never fails and prints some weird output to the screen. ☺??↨??$error = 7 niet vinden. That's all, it's an annoyance nothing more because it doesn't affects the batch in any way, and it can simply be ignored. But it's weird. I discovered it can be suppressed if I add an echo before and after the call, not just any echo will do the trick it matters how many characters are being echoed aswell ! I've never seen this before, and I assume noone has. Doing something like this seems to solve it. Changing the function requires recalibration of the number of chars in the echo command.

Code: Select all

	>nul echo.çomm
	:breakif () 							%=InDirect call=%
	::(
		if %$Direct% neq 0 goto :breakif "()"
		::
		%@DdefEcho% !$for! ( !$param! ) %%$macro%% &%@pause%
		::
		(
			Endlocal

			%$for% ( %$param% ) %$macro%
		)
		::
		%@DequForT% ( "returned from indirect" ) %@21necho_#AsDLT%
		%@DequPause%
	::
	goto :fin "()"

	:breakif () 							%=Direct call=%
	::(
		%@DdefEcho% %%$macro%% &%@pause%
		::
		(
			Endlocal

			%$macro%
		)
		::
		%@DequForT% ( "returned from direct" ) %@21necho_#AsDLT%
		%@DequPause%
	::
	:fin ()
	::)
	>nul echo.çomm
Now is that weird or is that weird !
Definitly a cmd v2 bug, too bad I am the only one who is having problems with it. :o
Last edited by Ed Dyreen on 14 Jul 2011 12:52, edited 1 time in total.

dbenham
Expert
Posts: 2165
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#11 Post by dbenham » 10 Jul 2011 15:50

That is an ugly intermittent XP bug :!: Sometimes my XP machine is in a mode where it doesn't show up. Other times it shows up every time. Using nested FOR loops seemed to be one trigger that causes it to show up on my machine. Since Ed is constantly using FOR loops with his macros, I'm not surprised he sees it a lot.

With a casual Google search I found only one other reference to it from 2006. http://groups.google.com/group/alt.msdo ... d6acf87c79

jeb wrote:But the cause seems to be the ' character.

If I change it to " and remove the usebackq it works always
Actually the problem is the naked , within the IN () clause. I am also able to reproduce the problem if the IN () clause contains ; = or space. I assume it can also fail with a tab character.

I think you can safely use USEBACKQ as long as the offending characters are either escaped or enclosed within double quotes "". I've yet to see it fail under these circumstances.

Code: Select all

@echo off
setlocal enableextensions enabledelayedexpansion
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('a,b,c') do @echo('a,b,c' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('a;b;c') do @echo('a;b;c' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('a=b=c') do @echo('a=b=c' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('a b c') do @echo('a b c' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('"a,b,c"') do @echo('"a,b,c"' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('"a;b;c"') do @echo('"a;b;c"' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('"a=b=c"') do @echo('"a=b=c"' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('"a b c"') do @echo('"a b c"' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('a^,b^,c') do @echo('a^^,b^^,c' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('a^;b^;c') do @echo('a^^;b^^;c' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('a^=b^=c') do @echo('a^^=b^^=c' -^> a=%%a b=%%b c=%%c
for /f "usebackq eol=, tokens=1-26 delims=,;= " %%a in ('a^ b^ c') do @echo('a^^ b^^ c' -^> a=%%a b=%%b c=%%c

Output on XP:

Code: Select all

'a,b,c' -> a=a b=b c=c
The system cannot find the file ♦?♀g♣?ê??? .
'a;b;c' -> a=a b=b c=c
The system cannot find the file ♦ê♀&♣(▬?§?d.
'a=b=c' -> a=a b=b c=c
The system cannot find the file ♦A♀Q♣àN?§?d.
'a b c' -> a=a b=b c=c
The system cannot find the file ♦?♀|♣`§?§?-.
'"a,b,c"' -> a="a b=b c=c"
'"a;b;c"' -> a="a b=b c=c"
'"a=b=c"' -> a="a b=b c=c"
'"a b c"' -> a="a b=b c=c"
'a^,b^,c' -> a=a b=b c=c
'a^;b^;c' -> a=a b=b c=c
'a^=b^=c' -> a=a b=b c=c
'a^ b^ c' -> a=a b=b c=c

The code always works on my Vista machine without error.

Dave Benham

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

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#12 Post by jeb » 10 Jul 2011 16:24

I suppose the main question should be, why there is a file access?
The system cannot find the file ♦?♀g♣?ê??? .


Perhaps it's the combination between ' and usebackq, that trigger this problem.

jeb

dbenham
Expert
Posts: 2165
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#13 Post by dbenham » 11 Jul 2011 08:42

jeb wrote:I suppose the main question should be, why there is a file access?
The system cannot find the file ♦?♀g♣?ê??? .

Perhaps it's the combination between ' and usebackq, that trigger this problem.

Perhaps...

But the intermittent behavior reminds me of C programming bugs dealing with bad or unitialized pointers and/or memory over-runs. In those cases the resulting bizarre behavior often has no obvious relevance to the actual bug.

I'm thinking the file access message is simply an unfortunate side effect of the underlying bug in XP CMD.EXE.

Dave Benham

dbenham
Expert
Posts: 2165
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#14 Post by dbenham » 11 Jul 2011 18:53

I managed to demonstrate the XP FOR /F bug without USEBACKQ and without using an apostrophe :!:

test.bat

Code: Select all

@echo off
for /f "tokens=1-26 delims=,;= " %%a in ("a%~1b"%~1c"") do @echo(Testing %1: a=%%a b=%%b c=%%c

test2.bat

Code: Select all

@echo off
for /l %%n in (1 1 5) do call test ","
for /l %%n in (1 1 5) do call test ";"
for /l %%n in (1 1 5) do call test "="
for /l %%n in (1 1 5) do call test " "

test2.bat Output:

Code: Select all

Testing ",": a=a b=b" c=c"
Testing ",": a=a b=b" c=c"
The system cannot find the fileO♣( ?o?e.
Testing ",": a=a b=b" c=c"
The system cannot find the fileO♣( ? ?e.
Testing ",": a=a b=b" c=c"
The system cannot find the file?♣`9?o?y.
Testing ",": a=a b=b" c=c"
The system cannot find the file?♣↑ ? ┘ .
Testing ";": a=a b=b" c=c"
Testing ";": a=a b=b" c=c"
The system cannot find the fileO♣`Q? ?e" c"".
Testing ";": a=a b=b" c=c"
The system cannot find the fileA#?o?C.
Testing ";": a=a b=b" c=c"
The system cannot find the file,?n.
Testing ";": a=a b=b" c=c"
The system cannot find the file?♣? ? ┘ .
Testing "=": a=a b=b" c=c"
Testing "=": a=a b=b" c=c"
The system cannot find the file?♣8→?è?→.
Testing "=": a=a b=b" c=c"
The system cannot find the file?♣↑ ?û?o.
Testing "=": a=a b=b" c=c"
The system cannot find the file?♣pÑ?$?Ñ.
Testing "=": a=a b=b" c=c"
The system cannot find the file?♣pÑ?$?Ñ.
Testing " ": a=a b=b" c=c"
Testing " ": a=a b=b" c=c"
The system cannot find the file?♣???i".
Testing " ": a=a b=b" c=c"
The system cannot find the fileO♣`Q?o?e" c"".
Testing " ": a=a b=b" c=c"
Testing " ": a=a b=b" c=c"
The system cannot find the file♦♣P#?§?§.

I also managed to get the bug using a <tab> character as predicted (not shown)

I really think the XP FOR /F bug only manifests itself when the parser encounters unescaped / unquoted token delimiters within the IN () clause.

Dave Benham

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

Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind

#15 Post by jeb » 14 Jul 2011 05:46

Hi Dave,

dbenham wrote:I really think the XP FOR /F bug only manifests itself when the parser encounters unescaped / unquoted token delimiters within the IN () clause.

I think you could be right.

Sometimes the parser seems to be unsure what is a text and what is a file.

Code: Select all

FOR /f "delims=" %%a in ("one two" ) do echo %%a
FOR /f "delims=" %%a in ("one two" three   ) do echo %%a


[quote="out]one two
The file "one two" three" can't be found.[/quote]

jeb

Post Reply