Problems with script which call another file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Problems with script which call another file

#16 Post by alan_b » 20 May 2011 15:01

Ed Dyreen wrote:@alan_b
I respect your capability,
but for me to use these double colon tricks would be venturing beyond my capabilities,
and I would fall flat on my face.

Is this ironic :(

No. Not ironic.
At one time I much preferred :: instead of REM because the information in the comment was more visible:-

4 little spots was far less obtrusive than the solid lines which formed 3 separate letters ;

4 little spots disabled all subsequent code - I once found that REM failed.
Not sure now, I think it might have been a code of the form
REM DIR FILE >> text.txt
and the DIR command was disabled by REM but a blank line was appended to text.txt.
Or it could have been the other way round ! !
BUT then I was tripped up by parentheses failing when they contained double colons or a label,
so I am perhaps over sensitive to the dangers of colons within parentheses.

"Better to remain silent and be thought a fool than to speak out and remove all doubt."
Maybe, well I won't speak to you then :lol:


I thought it was self evident I was NOT implying that you were a fool,
but carefully explaining that I would make foolish mistakes if I tried these tricks.

I appreciate Jeb's link to an explanation, especially his final post where he stated
"Ok, the last one is really hardcore (It costs me some hours to develop it)." and
"But why the second sample only takes the "THIS_TOKEN_IS_IGNORED" ? And if I change the ":comment" with something other like "echo", both versions works the same way :?:"

There is no way that I could be successful in utilising that information.

Ed, I appreciate clever tricks at which you excel,
but prefer to avoid wasting time trying to understand obfuscated code that is doing nothing.

It may be good training but if someone needs help to achieve an end result the simplest is the best.

Give them a simple solution that can be understood and when they see that what they asked for is NOT exactly what they really need,
then they may be able to fix the code to do what they want for themselves instead of passively coming back for an expert redo on what is way beyond their capabilities.

Regards
Alan

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

Re: Problems with script which call another file

#17 Post by Ed Dyreen » 20 May 2011 16:06

BUT then I was tripped up by parentheses failing when they contained double colons or a label,
so I am perhaps over sensitive to the dangers of colons within parentheses.

REM DIR FILE >> text.txt
and the DIR command was disabled by REM but a blank line was appended to text.txt.


The failure of rem in this case is known to me. Thats why I use '::' Seems like I am doing the opposite of what you are doing.

Code: Select all

N>rem hello >> txt
N>:: hello >> txt
N>

Does not produce a file (under normal conditions but is possible). I've seen some strange files myself too . But i think it only happens if the program is bugged.

This code will crash your batch.
::for %%! in ( ERR.Get.ComputerName ) do %%%~!% %(>nul)%
This will work
::for %%! in ( ERR.Get.ComputerName ) do %%%!% %(>nul)%

I am having a problem with ':'

Code: Select all

::--------------------------------------------------------------------------------------------------------------------------
:: Pre Define Create.Object                                     >>
::(
   set ^"@Create.Object=( %\n2%^

      Setlocal EnableDelayedExpansion %\n2%^

      set "Object.Name=%%~a" %\n2%^
      set "Object.Extension=%%~b" %\n2%^
      set "Object.StdIn=%%~c" %\n2%^
      set "Object.StdOut=^!Object.Name^!.^!Object.Extension^!" %\n2%^
      set "Object.Error=%%~d" %\n2%^

      if /i ["^!Object.Extension^!"] == ["File"] ( %\n2%^

         %For_aToken_Macro% (  '"Host"¦"!FullPath.LocalHost.SCRIPT!"¦"1"' ) !@Create.File! ^>nul %\n2%^

      ) %\n2%^

      if /i ["^!Object.Extension^!"] == ["FileName"] ( %\n2%^

         %For_aToken_Macro% (  '"Host"¦"!FullPath.LocalHost.SCRIPT!"¦"1"' ) !@Create.FileName! ^>nul %\n2%^

      ) %\n2%^

      %For_rToken_Macro% ( %\n2%^

         '"^!Object.StdOut^!"¦"^!Error^!"' %\n2%^

      ) do ( %\n2%^

         Endlocal %\n2%^

         if "%%~a.%%~b" neq "." ( %\n2%^

            set "%%~a.%%~b=%%~r" %\n2%^

         ) else    set "%%~a.%%~b=" %\n2%^

         set /a Error = %%~s %\n2%^

         echo. %\n2%^
         echo. %\n2%^
         echo. @Create.Object: '%%~a.%%~b' %\n2%^
         echo.  Object.StdOut: '%%~r' %\n2%^
         echo.  Object.Error : '%%~s!' %\n2%^
      ) %\n2%^
   ) ^&( echo. ^&echo. ^&echo. @Create.Object ^&echo.hello)"
::)
::
:: Post Define Create.Object                                     <<
::--------------------------------------------------------------------------------------------------------------------------


One of the last commands is :
'echo. @Create.Object'
It needs to be
'echo. @Create.Object:'
but whenever I try to use it like that it fails ! A ')' symbol is stripped from the macro at definition phase .
Gues the macro is misidentifying a label because '::' will work but echo. isnt executed then :?

Code: Select all

                        set /a Error = %~s

                        echo.
                        echo.
                        echo. @Create.Object: '%~a.%~b'
                        echo.  Object.StdOut: '%~r'
                        echo.  Object.Error : '%~sObject.Error!
echo.hello
        )_
<< niet verwacht op dit moment.
Z:\ADMIN\REPAIR\OS\ED's_WinXPPro32x86\EDInstall_WinXPPro32x86 beta v1>


I really have no clue why it acts like this ? the macro is called like
for %%a *** in ( *** ) do ( %macro% )
Because the macro needs to echo. messages on errors
for %%a *** in ( *** ) do ( ( *** ) &(echo. @Create.Object:) )
At the same time I need the ability to send to nul
for %%a *** in ( *** ) do ( %macro% >nul )
Which is the same as
for %%a *** in ( *** ) do ( ( *** ) &(echo. @Create.Object:) >nul )

Solved it, problem with the brackets ()
%forAmacro% ( '"Host"¦"File"¦"!FullPath.LocalHost.SCRIPT!"¦"1"' ) do %Test.Macro%

Goodmorning DOS :D What problem do I have today :x

Post Reply