Page 1 of 1

space is added to the file if it is after the extension

Posted: 10 Nov 2023 11:11
by miskox
See this:

Code: Select all

@echo off
set str=some text
echo %str%>tmp.tmp &REM space before the & sign!!!
result:

After the 'text' there is a space.

Code: Select all

some text 
Strange.

Saso

Re: space is added to the file if is after the extension

Posted: 10 Nov 2023 12:28
by jeb
Hi Saso,

not quite strange, it's the expected behavior.

The rule is: If a redirection to a stream is found, store it in a buffer (one buffer for each stream), remove the redirection text from the command line.

What same mean? Some examples

Code: Select all

@echo off

del /s test.txt 2> NUL > NUL

@echo on

echo Test1>>test.txt&REM
echo Test2>>test.txt &REM
echo Test3>>     test.txt&REM
echo>>test.txt Test4&REM
echo Test5>>void.txt>>test.txt&REM
>* > ::$ 2>errorX.txt echo Test6>>void.txt>>NUL>>test.txt=2>Error.txt&REM

@echo off
for /F "delims=" %%a in ('findstr /N "^" test.txt') do (        
  echo %%a'
)
output wrote:C:\Users\jeb\x>..\redir.bat
C:\Users\jeb\x>echo Test1 1>>test.txt & REM
C:\Users\jeb\x>echo Test2 1>>test.txt & REM
C:\Users\jeb\x>echo Test3 1>>test.txt & REM
C:\Users\jeb\x>echo=Test4 1>>test.txt & REM
C:\Users\jeb\x>echo Test5 1>>test.txt & REM
C:\Users\jeb\x>echo Test6 1>>test.txt 2>Error.txt & REM
C:\Users\jeb\x>echo Test7 1>>test.txt 2>Error.txt & REM
1:Test1'
2:Test2 '
3:Test3'
4:Test4'
5:Test5'
6:Test6'
7:Test7'

Re: space is added to the file if it is after the extension

Posted: 11 Nov 2023 09:36
by miskox
Thanks Jeb!

Saso