Printing to file in for loop using Batch Script

Viewed 54

I am trying to write to xml file using a batch script, however it only writes the last loop to the file. The variable Project_Choice is just two comma separated strings. It prints to the console correctly, however writes only the last loop in the xml file. Where am I going wrong?

for %%i in (%Project_choice%) do (                            
    echo(^<?xml version="1.0" encoding="utf-16" ?^>
    echo(^<testConfiguration^>
    echo(^<TestEvents^>
    echo(^<TestEvent^>%%i^</TestEvent^>
    echo(^</TestEvents^>
    echo(^</testConfiguration^>
)> C:\cijobscript\Test.xml
1 Answers

> creates a new file. >> appends to an existing file. Change the > to >> BUT this will append the new data to any existing file, so you'd need to delete it first.

-- OR --

use

(for .... do (echo....))>filename

to create a new file

Note here the for command itself is within parentheses.

Related