billbaggy
billbaggy

Reputation: 31

Windows Batch File Redirect Output

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.

Upvotes: 2

Views: 3805

Answers (2)

billbaggy
billbaggy

Reputation: 31

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

Upvotes: 0

Anders
Anders

Reputation: 101764

>>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%)

Upvotes: 2

Related Questions