The @ at the begining at the line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

The @ at the begining at the line

#1 Post by npocmaka_ » 16 Oct 2015 00:17

(Tested only on Win8.1x64)

Some playing with @.

I'd expected to act like delimiter but it is different.

this line crashes the console (after the command is execute - visible if rem is changed to echo # or notepad):


{bat with many @-s}

Maximum @s that I can put in front of the line is 903 (far from the limit of 8191 limit)

When the the @s are piped the limit is 270:

{bat with piped @s}


while call @rem will pass and call @@rem will produce error but these examples are ignoring the @ and missing operand:

Code: Select all

call @@ @@
if 1==1 @@ @@@
for %%# in (.) do @@ @@



Is @ treatened like command?


Only single @ can be put at the beginning of the line and to be recognized by goto/call

Code: Select all

@echo off

goto :label1
echo --
@:label1

goto :label2
echo --
@@:label2

Last edited by npocmaka_ on 16 Oct 2015 16:48, edited 1 time in total.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: The @ at the begining at the line

#2 Post by penpen » 16 Oct 2015 02:58

The maximum "allowed" '@' characters on my Win XP home (SP3, 32bit) is 2325 (no matter if piped or not; on my win8 the maximum is 4298 - both piped and 'normal'), so this is working:

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
:: create 4096 '@' characters
set "test=@@@@"
set test=!test:@=%test:@=@@%!
set test=!test:@=%test:@=@@@@%!

%test:~-2325%echo a

endlocal
Windows XP:
But if i manually start this batch file ("test1.bat") 9 times from my desktop path ("C:\Dokumente und Einstellungen\...\Desktop>") then the cmd also closes.
If create a "z"-drive (using "subst z: .") i am able to start this batch 14 times.
Windows 8 - 32 bit:
started it 100 times - seems it runs always.


Windows XP:
The file is also proecessed completely if there are more '@' characters, but it is closed at the end (try any batch source with "pause" as a last line, inclusing goto, call and run executables):

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
:: create 4096 '@' characters
set "test=@@@@"
set test=!test:@=%test:@=@@%!
set test=!test:@=%test:@=@@@@%!

%test:~-2326%echo a

endlocal
echo internal command
cmd /q /C echo external command
call :function
goto :label

:function
echo function
goto :eof

:label
echo Good bye!
pause


One could also 'rescue' the shell 'influenced' with up to 2376 '@' characters with 2 lines containing exactly 2325 '@' characters (all other tested amount failed at least on my system):

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
:: create 4096 '@' characters
set "test=@@@@"
set test=!test:@=%test:@=@@%!
set test=!test:@=%test:@=@@@@%!

%test:~-2376%echo a
%test:~-2325%echo a
%test:~-2325%echo a

endlocal


penpen

Edit: I have minimized the line length.
Edit2: Added more information.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: The @ at the begining at the line

#3 Post by penpen » 16 Oct 2015 16:10

npocmaka_ wrote:Is @ treatened like command?
I guess no, because you could use the tilde character within commands, but not with @:

Code: Select all

@ echo abc
for %%a in (1 2 3) do @if a == a echo %%a
^f^o^r %%a in (1 2 3) do @^i^f a == a ^e^c^h^o %%a
^@ echo def
So i think it is just a special character.

penpen

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: The @ at the begining at the line

#4 Post by npocmaka_ » 16 Oct 2015 17:17

then just it's something about IF FOR and CALL parsers


I thought that call @rem but in fact nothing like call @command is executed same as call (command)
One more strange behaviour:

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

Re: The @ at the begining at the line

#5 Post by jeb » 17 Oct 2015 09:43

I only knows about some other behaviour of the @ sign.

You can mix it with "normal" delimiters like you want.

But when you use redirections, the @ has to be in front of the redirection, else the command fails.

Code: Select all

@echo off

,;  ;=;,;=@,;  ;=;,;=@,;  ;=;,;=@;,;  ;=;,;=@@echo line1
@@ <NUL ,;  ;=;,;= echo Line2
<NUL @echo Line3

Post Reply