Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Printing to file in for loop using Batch Script

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

> 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading