Re: ☺?♥♠a♀???☻?☻ for weirdness ♠☺??↨??$error = 7 niet vind
Posted: 16 Jul 2011 09:08
'
XP uses cmd v2, more recent versions use v3.
I've run my macros against XP's ServicePack3, bad news though, the bug still pops up.
But I succesfully worked around the problem for macros that are called directlyI figured I don't need echo to avoid the problem, It also works with a rem statement, I now use this command "rem .çommas":
I tried to work around the problem for macros that are called indirectly, and I succeeded in 95% of the cases,
too bad it don't work ALL the time.I call into it using this macro:
And this is a macro that uses it and sometimes encounters the bug:
I'm sorry it's big &obfuscated, but I hope it gives the experts an idea of what I'm trying to achieve. I wish I could post a SMALL example, the problem is, this behavior only occurs with complex macros
OUTPUT:Don't ask me why or how, I have absolutely no idea what I'm dooing.
If someone want's to see the bug in action using the full sourcecode,
browse to scriptingpros and download the "Pre release" attachment at the bottom of the page if it's there,
otherwise download the release version...
http://www.scriptingpros.com/viewtopic.php?f=152&t=70
XP uses cmd v2, more recent versions use v3.
I've run my macros against XP's ServicePack3, bad news though, the bug still pops up.
But I succesfully worked around the problem for macros that are called directly
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 tried to work around the problem for macros that are called indirectly, and I succeeded in 95% of the cases,
too bad it don't work ALL the time.
Code: Select all
::--------------------------------------------------------------------------------------------------------------------------
::
:: exec any external command v initialize functions
::
::(
set "$DefinedFLAG=%*"
::
if defined @DdefEcho (
%@DequEcho% star : '%*'
%@DequEcho% $DefinedFLAG: '%$DefinedFLAG%'
)
::
if defined $DefinedFLAG (
%@forTS% ( "%~1" ) %@TraceIn%
rem .çommas
call :%$DefinedFLAG%
rem .çommas
%@DequPause%
%@TraceOut%
exit /b !$error!
)
::
goto :skip "()"
%@endoftest%
:skip ()
::)
::--------------------------------------------------------------------------------------------------------------------------
::--------------------------------------------------------------------------------------------------------------------------
%@Pre% §Functions
::(
::--------------------------------------------------------------------------------------------------------------------------
set "$Defines=§CallMacro"
::
set ^"$Usage.%$Defines%=^
% % Usage: %%@forEL%% ( 'r$for, o$Macro o?params' ) %%@CallMacro%% %$n1c%
% % input: %$n1c%
% % r$for : supports simple for's, complex: @forU, @forEL %$n1c%
% % o$Macro : Name of macro that will be executed %$n1c%
% % o?params: Parameters to pass to macro that will be executed %$n1c%
% % ToConsole: %$n1c%
% % None: the output cannot be redirected. %$n1c%
% % Return: %$n1c%
% % $error: from called macro. "
::
goto :skip "()"
::
:: Do not remove the "rem .çommas" lines, they prevent the for çommas bug/annoyance on XP !
::
:§CallMacro "()"
::(
rem %@Ddef% set "$Debug.Sub=!$Trace!"
::
Setlocal EnableDelayedExpansion %=Prevent variable conflicts with caller=%
set "$param=%*"
::
%@DequForE% ( "$param=!$param!_" ) %@21necho_#AsDLT%
if ["!$param:~0,1!"] == [""^"] if ["!$param:~-1!"] == [""^"] set "$param=!$param:~1,-1!"
if defined $param set "$param=!$param:?=i!" %$n1c%
::
%@DequForT% ( "" "process $param:" ) %@21necho_#AsDLT%
%@DequForE% ( "$param=!$param!_" ) %@21necho_#AsDLT%
%@DequForT% ( "" "split $for, $macro, $param:" ) %@21necho_#AsDLT%
::
set "$for="
set "$macro="
set /a $trigger = 0
::
%@forTS% (
!$param!
) do if defined $for ( %=Declare $for=%
::
if defined $macro ( %=Declare $macro=%
::
if !$trigger! equ 0 ( %=Declare $param=%
::
set "$param=%%!"
::
set /a $trigger = 1
) else set "$param=!$param! %%!"
) else set "$macro=%%~!"
) else set "$for=%%~!"
::
if not defined $macro (
::
set /a $Direct = 1
::
set "$param="
) else set /a $Direct = 0
::
%@DequForE% ( "$for=!$for!_" ) %@21necho_#AsDLT%
%@DequForE% ( "$macro=!$macro!_" ) %@21necho_#AsDLT%
%@DequForE% ( "$param=!$param!_" ) %@21necho_#AsDLT%
%@DequPause%
set /a $delims = 0
%@DequForT% ( "" "split @forU $param;" ) %@21necho_#AsDLT% %=split @forU $param;=%
::
if /i ["!$for!"] == ["@forU"] (
::
set /a $trigger = 0
::
%@forTS% (
!$param!
) do if !$trigger! equ 0 ( %=Declare $param=%
::
set "$param=%%!"
::
set /a $trigger = 1
) else set "$param=!$param!, %%!"
::
set /a $delims = 1
) else if /i ["!$for!"] == ["@forEL"] (
::
set /a $delims = 1
)
%@DequForT% ( "" "split for $delims;" ) %@21necho_#AsDLT% %=split @for $delims;=%
if !$delims! equ 1 (
::
set "$param='!$param!'"
) else set $param="!$param!"
%@DequForT% ( "eval $for;" ) %@21necho_#AsDLT% %=eval ( $for )=%
::
for %%! in ( "%$for%" ) do set "$for=!%%~!!"
%@DequForT% ( "eval $macro;" ) %@21necho_#AsDLT% %=eval ( $macro )=%
::
if !$Direct! equ 1 (
::
set "$macro=!$for!"
::
set "$for="
) else for %%! in (
"%$macro%"
) do set "$macro=!%%~!!"
::
%@DequForE% ( "$Direct=!$Direct!_" ) %@21necho_#AsDLT%
%@DequForE% ( "$macro=!$macro!_" ) %@21necho_#AsDLT%
%@DequForE% ( "$for=!$for!_" ) %@21necho_#AsDLT%
%@DequForE% ( "$param=!$param!_" ) %@21necho_#AsDLT%
rem .çommas
:breakif () %=InDirect call=%
::(
if %$Direct% neq 0 goto :breakif "()"
::
rem .çommas
%@DdefEcho% !$for! ( !$param! ) %%$macro%% &%@pause%
::
(
Endlocal
rem .çommas çommas çommas
%$for% ( %$param% ) %$macro%
rem .çommas çommas çommas
)
::
%@DequForT% ( "returned from indirect" ) %@21necho_#AsDLT%
%@DequPause%
rem .çommas
::
goto :fin "()"
::)
:breakif () %=Direct call=%
::(
%@DdefEcho% %%$macro%% &%@pause%
::
(
Endlocal
%$macro%
)
::
%@DequForT% ( "returned from direct" ) %@21necho_#AsDLT%
%@DequPause%
::
:fin ()
::)
rem .çommas
::
exit /b !$error!
::
call :§CallMacro "()"
:skip ()
::)
::--------------------------------------------------------------------------------------------------------------------------
Code: Select all
::--------------------------------------------------------------------------------------------------------------------------
set "$Defines=@CallMacro" &set "$Details="
::
:: calls a function §CallMacro that calls a macro, use as a breakpoint for macros that would otherwise pass the 8k limit
::
2>%@DNul% ( %@forA% ( '"%$Defines%"¦"EnableDelayedExpansion"' ) %@Macro.Begin% )
::(
set ^"$Usage.%$Defines%=^
% % Usage: %%@forEL%% ( 'r$for, o$Macro, o?params' ) %%@CallMacro%% %$n1c%
% % input: %$n1c%
% % r$for : only supports looptokens like @forEL, @forU, @forTS %$n1c%
% % r$Macro : Name of macro that will be executed %$n1c%
% % o?params: Parameters to pass to macro that will be executed %$n1c%
% % ToConsole: None %$n1c%
% % Return: %$n1c%
% % $error: from called macro. "
::
set ^"%$Defines%=do ( call "^!$UDF.FullPathFile^!" §CallMacro "%%~^!" )"
::
%@forEL% ( '@forU, @TestforUmacro, $This, "$Works", "This=Working"' ) %@CallMacro%
%@forEL% ( '@Delayed' ) %@CallMacro%
::)
2>%@DNul% %@Macro.End%
::
%@COMMIT%
::--------------------------------------------------------------------------------------------------------------------------
::
goto :skip "()"
%@endoftest%
:skip ()
Code: Select all
::--------------------------------------------------------------------------------------------------------------------------
set "$Defines=@Move.Object" &set "$Details=Move a previously declared object"
::
2>%@DNul% ( %@forA% ( '"%$Defines%"¦"EnableDelayedExpansion"' ) %@Macro.Begin% )
::(
set ^"$Usage.%$Defines%=^
% % Usage: %%@forU%% ( 'r#Name, r?NewLocation, o#error.bool' ) %%%$Defines%%% %$n1c%
% % input: %$n1c%
% % r#Name : Name of object %$n1c%
% % r?NewLocation: New physicall location of object %$n1c%
% % o#error.bool : 0 for always return, 1 for always PANIC %$n1c%
% % ToConsole : Contents of $Name %$n1c%
% % Return: %$n1c%
% % $error: 0 for succes, 1 for error "
::
% % set ^"%$Defines%=!@Udelim! ( %$n1c%
% % %=if defined $Debug.Sub set "$Debug.Sub=!$Defines!"=% %$n1c%
% % !@forEL! ( '@forEL, @LeadIn, %$Defines%, "r#Name=%%~a", "r?NewLocation=%%~b", "o#error.bool=%%~c"' ) !@CallMacro! %$n1c%
% % !@forEL! ( '@forU, @Object.Chk.Exist, "^!$Name^!", "^!$error.bool^!"' ) !@CallMacro! ^>nul %$n1c%
% % !@forU! ( '"^!$Name^!"' ) !@Object.Extend! ^>nul %$n1c%
% % !@n2echo! %$Defines%: '^^^!$Name^^^!' '^^^!$Extension^^^!' %$n1c%
% % if ^^^!$error^^^! equ 0 if /i ["^!$Extension^!"] == ["AsDir"] ( %$n1c%
% % !@forEL! ( '@forU, @Move.AsDir, "^!$Name^!", $NewLocation, "^!$error.bool^!"' ) !@CallMacro! %$n1c%
% % ) else if /i ["^!$Extension^!"] == ["AsFile"] ( %$n1c%
% % !@forEL! ( '@forU, @Move.AsFile, "^!$Name^!", $NewLocation, "^!$error.bool^!"' ) !@CallMacro! %$n1c%
% % ) %$n1c%
% % !@IfErrorBoolExit! %$n1c%
% % !@nError! %$n1c%
% % !@LeadOut! %$n1c%
% % )"
::)
2>%@DNul% %@Macro.End%
::
%@COMMIT%
::
%@forU% ( '$aFile, "C:\This Works\This Works\This Works.TMP", 1' ) %@Move.Object%
%@forU% ( '$aDir, "C:\This Works", 1' ) %@Move.Object%
::--------------------------------------------------------------------------------------------------------------------------
::
goto :skip "()"
%@endoftest%
:skip ()
OUTPUT:
Code: Select all
>> Pre Define @Move.Object, Move a previously declared object
<< Post Define @Move.Object, Move a previously declared object [OK]
@Move.Object: '$aFile' 'AsFile'
@Move.AsFile: '$aFile' 'AsFile'
$FullPathFile.OLD: 'C:\This Works\This Works.TMP'
$FullPathFile.NEW: 'C:\This Works\This Works\This Works.TMP'
[ok:0]
[ok:0]
@Move.Object: '$aDir' 'AsDir' Kan bestand bool%▬♦ niet vinden.
@Move.AsDir: '$aDir' 'AsDir'
$FullPath.OLD: 'C:\This_Works'
$FullPath.NEW: 'C:\This Works'
0 bestand(en) gekopieerd
[ok:0]
[ok:0]
endoftest Druk op een toets om door te gaan. . .
If someone want's to see the bug in action using the full sourcecode,
browse to scriptingpros and download the "Pre release" attachment at the bottom of the page if it's there,
otherwise download the release version...
http://www.scriptingpros.com/viewtopic.php?f=152&t=70