1.

Solve : Write < and > to a file with batch?

Answer»

Hi there
I wonder: how do you write the < and > signs to a (text) file, using batch under windows XP

if I use this code:

>>test.xml echo This is a test

The batch file closes, before I can even see the error.
I think the error is caused because of the < sign that is near the >> command that writes the xml file wich causes confusion for the computer. Is there any way I could solve this problem?

With kind regards

MikiCertain characters like <, >, %, |, etc which have special meaning in DOS/NT command line and batch, need to be "escaped" with a caret character (^) in front like this if you want them to show up in files.

>>test.xml echo this will appear in file ^This is a test^

Quote from: contrex on July 07, 2007, 02:23:47 AM

>>test.xml echo this will appear in file ^<TEST1^>This is a test^</test1^>

This solved my problem.

Thank you so much for your quick help, contrex

Cheers and greets You're welcome. When I wrote "... if you want them to show up in files" of COURSE I should have added "or on the screen"I have another question, if u don't mind

I'd like to somehting like this

Code: [Select]@echo off
set towrite=test (this is just a simple example, in my batch it reads from a file etc and then the batch sets towrite=test)
>>test.xml ^<%towrite%^>
pause
So, I'd like to write my towrite between the < > tags, how do I do that?

Code: [Select]@echo off
set test=test
>>test.xml ^<^%test^%^>
pause
The above code doesn't workYour code

@echo off
set test=test
>>test.xml ^<^%test^%^>
pause

1. You have set the environment variable named test to hold the string "test".

2. A SIDE issue - it can lead to bad confusion if you call variables the same as their contents.

3. You missed out "echo" in your third line which should look like this I guess

>>test.xml echo ^<^%test^%^>

4. However this will result in nothing being written to test.xml since you have escaped the % signs surrounding the variable name.

5. If you remove the carets in front of the % signs

>>test.xml echo ^<%test%^>

test.xml holds this line

<test>

6. If you escape the % signs you no longer have a variable.




Discussion

No Comment Found