A big question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

A big question

#1 Post by darioit » 08 Sep 2010 04:05

I was going crazy about this issue

why this code works

Code: Select all

IF %REC4% EQU y (
CALL :check_total %2 %~nx2
)   ELSE (
   >> %REP%\%SEND%.%O%.%REP% ECHO.%BLABLA3%
   CALL Routine_Info.BAT %1 %~nx2
   >> %LOGS%\LOG_%DD0%.LOG ECHO 0 %DD2% %shh1%:%smm1%:%sss1%.%sms1% %~nx2 %DEAL% %MI% %O% %CX% %CP% %~nx2 %~t2 %~z2
   MOVE /Y %nome_file_input% %SND%
)


instead this one doesn't work (the only differences is :: in the MOVE command

Code: Select all

IF %REC4% EQU y (
CALL :check_total %2 %~nx2
)   ELSE (
   >> %REP%\%SEND%.%O%.%REP% ECHO.%BLABLA3%
   CALL Routine_Info.BAT %1 %~nx2
   >> %LOGS%\LOG_%DD0%.LOG ECHO 0 %DD2% %shh1%:%smm1%:%sss1%.%sms1% %~nx2 %DEAL% %MI% %O% %CX% %CP% %~nx2 %~t2 %~z2
   :: MOVE /Y %nome_file_input% %SND%
)


Thanks

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

Re: A big question

#2 Post by jeb » 08 Sep 2010 04:17

In a paranthesis block it is not allowed to place a label as the last command.
a :: is used like a comment, but it is an uncallable label

If you use "rem" instead, it should work.

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: A big question

#3 Post by darioit » 08 Sep 2010 04:21

For shure I use a REM instead double point, I have learned a new thing

Best
Dario

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

Re: A big question

#4 Post by orange_batch » 08 Sep 2010 05:21

Yes, :: should be used for text comments outside of brackets ().

rem should be used to disable a command for testing.

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

Re: A big question

#5 Post by jeb » 09 Sep 2010 13:55

But, rem is "stronger" than :: :)

Code: Select all

rem one two three ^
echo This line is displayed
:: one two three ^
echo This line will not displayed
rem "This is one token"^
echo This line will not displayed


With :: or other labels, the multiline always work.
With rem, it only works with the first token.

And in both variants all percents are expanded and can create errors

Code: Select all

rem one two three %~q1
output:
Die folgende Verwendung des Pfadoperators zur Ersetzung eines Batchparameters
ist ungültig: %~q1

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

Re: A big question

#6 Post by orange_batch » 09 Sep 2010 15:31

Yes, however I'm no fan of putting expandable variables or odd characters into comments unnecessarily. This shouldn't really be done. :)

If only DOS weren't rife with self-retardisms! lol

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: A big question

#7 Post by amel27 » 11 May 2011 00:26

During experiments with labels and parentheses has come across the "magic" line of code, that "dements" CMD.EXE if it place at the end of BAT file without trailing CRLF.

Code: Select all

(.&:Any Text

I hope that somebody can explain such behavior.

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

Re: A big question

#8 Post by jeb » 13 May 2011 03:13

Hi amel27,

amel27 wrote:During experiments with labels and parentheses has come across the "magic" line of code, that "dements" CMD.EXE if it place at the end of BAT file without trailing CRLF.
Code:
(.&:Any Text


It doesn't depend of CRLF it is an effect of the missing closing bracket.

A block with a missing closing bracket is completly ignored.

jeb

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: A big question

#9 Post by amel27 » 13 May 2011 04:06

jeb wrote:It doesn't depend of CRLF it is an effect of the missing closing bracket.

A block with a missing closing bracket is completly ignored.

Hi jeb,

effect in the following: with CRLF at the end of this line/file script finished quickly... but without CRLF "hang" on seconds (on XP) or generate system error (on Windows 7). FileMon tool on XP show thousands attempts of read operations outside of a file before script end.

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

Re: A big question

#10 Post by jeb » 13 May 2011 05:34

Ok,
in my last post I missed the point :?

But there is another interessting character effect with <NULL>.

If I place a <NULL> into my batch, the parser ignores some hundred characters after the <NULL> and restarts parsing later.

jeb

Post Reply