Reputation: 91
I have this code
rem Saved in D:\Temp\WriteText.bat
@echo off
@echo -ATTEDIT> ATTEDITChangeName.txt
@echo y>> ATTEDITChangeName.txt
@echo 36x24bdr>> ATTEDITChangeName.txt
@echo SUBTITLE>> ATTEDITChangeName.txt
@echo B209 11.5 TON BRIDGE ELEC LAYOUT 1 ^& 2>> ATTEDITChangeName.txt
@echo 612.9014,43.8533>> ATTEDITChangeName.txt
@echo 618.5063,35.8628>> ATTEDITChangeName.txt
@echo 109.9409,-6.7209>> ATTEDITChangeName.txt
@echo.>> ATTEDITChangeName.txt
@echo v>> ATTEDITChangeName.txt
@echo c>> ATTEDITChangeName.txt
@echo B209>> ATTEDITChangeName.txt
@echo B211>> ATTEDITChangeName.txt
@echo Next>> ATTEDITChangeName.txt
pause
that creates a text file and fills it with text. The problem is that the line that is intended to write the text "B209 11.5 TON BRIDGE ELEC LAYOUT 1 & 2" is not writing. Instead, it gets fed back on to the screen.
see link for screenshot http://gyazo.com/a97e6daaf4695b766659df426180c95b
We troubleshooted the problem as much as we could and found that this only happens when the number is single digit and both preceded and followed by only a space.
For example:
"1a" will work
"11" will work
"1." will work
" 1 " will not work
It is a requirement for the text read as " 1 & 2" verbatim. What can we do to achieve this?
Upvotes: 0
Views: 159
Reputation: 2277
Instead of specifying where each echo should go on every line
(i.e @echo -ATTEDIT> ATTEDITChangeName.txt
) , use this method of block form. It will solve the issue you've been having and clean up your code a bit.
@echo off
> ATTEDITChangeName.txt (
@echo -ATTEDIT
@echo y
@echo 36x24bdr
@echo SUBTITLE
@echo B209 11.5 TON BRIDGE ELEC LAYOUT 1 ^& 2
@echo 612.9014,43.8533
@echo 618.5063,35.8628
@echo 109.9409,-6.7209
@echo.
@echo v
@echo c
@echo B209
@echo B211
@echo Next
)
pause
Using > ATTEDITChangeName.txt
(as i did in my example) will override the current contents of the file, and replace it with what is in the (). If you wish to simple add text to the file, use >> ATTEDITChangeName.txt
.
While i'm unsure why this issue arises, the above code format will solve your problem and print all of the text to the text file.
Upvotes: 3
Reputation: 59238
The term 2>>
means that Windows will redirect StdErr output. To avoid that, move the redirection >>
to the front of the command like this:
echo>>ATTEDITChangeName.txt B209 11.5 TON BRIDGE ELEC LAYOUT 1 ^& 2
I agree, it looks a bit strange when you first use it that way, but it works.
Upvotes: 0