Page 1 of 1
Using echo redirects inside of a redirect? (Help)
Posted: 20 May 2012 15:49
by MasumeX
So I am trying to make my batch file create a new batch file, and then have the created batch file edit a text file. For instance-
echo This is an edit >> text.txt >> text.bat
How would I be able to accomplish this? If you need more information, just reply here. Please help!
Re: Using echo redirects inside of a redirect? (Help)
Posted: 20 May 2012 16:04
by MasumeX
Slight edit with that-
echo echo This is an edit >> text.txt >> text.bat
Re: Using echo redirects inside of a redirect? (Help)
Posted: 20 May 2012 16:19
by aGerman
Escape special characters.
^ to ^^
< to ^<
> to ^>
| to ^|
& to ^&
% to %%
Regards
aGerman
Re: Using echo redirects inside of a redirect? (Help)
Posted: 20 May 2012 16:23
by MasumeX
Thank you so much!

That was a big help! I finished it with-
echo echo This is an edit ^>^> text.txt >> text.bat
Question, Why does this work? I appreciate the solution, but could you help me learn why so I am better knowledged on this? Thank you!
Re: Using echo redirects inside of a redirect? (Help)
Posted: 20 May 2012 16:35
by aGerman
It's because each of these characters has its own functionality (escaping , redirection, piping, command concatenating, variable marking). You use >> to redirect the echo output to a file. To suppress their functionality and to let the cmd parse it as a literal character you have to escape them.
You could make some tests with the rules I gave you.
displays
These rules (except the last for %) are not valid for strings enclosed in quotation marks.
Also "EnableDelayedExpansion" changes the behavior for strings in variables and the exclamation mark is another special character that you have to escape in some cases.
Regards
aGerman
Re: Using echo redirects inside of a redirect? (Help)
Posted: 20 May 2012 16:46
by MasumeX
That is great to know; thank you so much for your help!