 |
☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vinden.
| Author |
Message |
|
Ed Dyreen
Expert
Joined: 16 May 2011 08:21 Posts: 1163 Location: Flanders_(Belgium)
|
 ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vinden.
☺ declare fit 3 tokens: Code: set "@forç=for /f "usebackq tokens=1-26 delims= " %%a in" execute split: Code: %@forç% ( '$var, 0, 999' ) %@GetRandom% result: Code: >> 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 Code: 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: 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. . .  Replace the comma and delims with ¦ and everything works  Code: %@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: ( 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 ?
|
| 18 Jun 2011 20:42 |
|
 |
|
jeb
Expert
Joined: 30 Aug 2007 08:05 Posts: 568 Location: Germany
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
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: FOR %%A (1) DO ( echo %%~ ) jeb
|
| 20 Jun 2011 04:53 |
|
 |
|
Ed Dyreen
Expert
Joined: 16 May 2011 08:21 Posts: 1163 Location: Flanders_(Belgium)
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
☺ Is this small enough for ya ? Code: @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: @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=999Druk op een toets om door te gaan. . . 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.
|
| 20 Jun 2011 07:30 |
|
 |
|
jeb
Expert
Joined: 30 Aug 2007 08:05 Posts: 568 Location: Germany
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
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
|
| 20 Jun 2011 07:45 |
|
 |
|
Ed Dyreen
Expert
Joined: 16 May 2011 08:21 Posts: 1163 Location: Flanders_(Belgium)
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
☺ 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 . 
|
| 20 Jun 2011 07:46 |
|
 |
|
jeb
Expert
Joined: 30 Aug 2007 08:05 Posts: 568 Location: Germany
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
Hi Ed, retested with XP32 (in a vm-box) Yes, you are right  , it fails ... sometimes I build a loop Code: @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: @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
|
| 20 Jun 2011 07:54 |
|
 |
|
Ed Dyreen
Expert
Joined: 16 May 2011 08:21 Posts: 1163 Location: Flanders_(Belgium)
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
☺ jeb to the resque  Code: @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. . .  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: %@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 %@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.
|
| 20 Jun 2011 08:02 |
|
 |
|
orange_batch
Expert
Joined: 01 Aug 2010 17:13 Posts: 442 Location: Canadian Pacific
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
viewtopic.php?f=3&t=1970&p=8581&hilit=usebackq#p8581Quote: 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. 
|
| 20 Jun 2011 12:57 |
|
 |
|
Ed Dyreen
Expert
Joined: 16 May 2011 08:21 Posts: 1163 Location: Flanders_(Belgium)
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
☺ I've had to do quite an effort to get it working the way I wanted on XP: Code: 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. 
|
| 20 Jun 2011 20:36 |
|
 |
|
Ed Dyreen
Expert
Joined: 16 May 2011 08:21 Posts: 1163 Location: Flanders_(Belgium)
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
☺ 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: ( 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: >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. 
Last edited by Ed Dyreen on 14 Jul 2011 12:52, edited 1 time in total.
|
| 04 Jul 2011 04:49 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 892 Location: United States (east coast)
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
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 ... d6acf87c79jeb 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: @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: '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
|
| 10 Jul 2011 15:50 |
|
 |
|
jeb
Expert
Joined: 30 Aug 2007 08:05 Posts: 568 Location: Germany
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
I suppose the main question should be, why there is a file access? Quote: The system cannot find the file ♦?♀g♣?ê??? . Perhaps it's the combination between ' and usebackq, that trigger this problem. jeb
|
| 10 Jul 2011 16:24 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 892 Location: United States (east coast)
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
jeb wrote: I suppose the main question should be, why there is a file access? Quote: 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
|
| 11 Jul 2011 08:42 |
|
 |
|
dbenham
Expert
Joined: 12 Feb 2011 21:02 Posts: 892 Location: United States (east coast)
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
I managed to demonstrate the XP FOR /F bug without USEBACKQ and without using an apostrophe test.bat Code: @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: @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: 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
|
| 11 Jul 2011 18:53 |
|
 |
|
jeb
Expert
Joined: 30 Aug 2007 08:05 Posts: 568 Location: Germany
|
 Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
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: 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
|
| 14 Jul 2011 05:46 |
|
|
Who is online |
Users browsing this forum: Google [Bot] and 8 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum
|
|
 |