2
votes

I need to output some parameter data from a batch file. I can redirect output, no problem. My issue is that I need to ouput something like

set value1=0
set value2=1
echo value1 = %value1%>>temp.txt
echo value2 = %value2%>>temp.txt

without a space after the parameter value

But this will not redirect properly due to CMD assuming that %value#% is the redirection value.

So if I do something like

echo value1 = %value1% >>temp.txt
echo value2 = %value2% >>temp.txt

It works, but I get a space after the parameter value and the next app that reads this file is not under my control and errors out with spaces after the values.

I must be missing something simple.

2

2 Answers

2
votes
>>temp.txt echo value1 = %value1%
>>temp.txt echo value2 = %value2%

(It is of course important to use quotes on the path if it contains spaces, >>"c:\some folder\file.txt" echo value1 = %value1%)

0
votes

I figured it out.

I just needed to quote the variable

echo value2 = ^%value2%>>temp.txt

Sorry about that, it kept "escaping" me (bad pun intended).