MortenOrum
MortenOrum

Reputation: 17

Batch writing to a file returns with ECHO is OFF

This never happened for me before, and I don't exactly understand why.

I used this code to set a variable from the text file:

set Drive=E
for /f "Delims=" %%a in (%Drive%:\Data\TestAttempt.txt) do (
set TEST=%%a
)

Then I tried to +1 to the %TEST%:

set /A TEST=TEST+1

At last I tried to put the new Variable into the same text file:

cd %Drive%:\Data
echo %TEST%> TestAttempt.txt

It worked before, and now I won't work. I don't understand why... It still returns ECHO is OFF. in the TestAttempt.txt file. It should be 2.

I have tried to create a space between %TEST% and >, but then I can't use +1.

Thanks.. :)

Upvotes: 0

Views: 169

Answers (1)

Magoo
Magoo

Reputation: 79983

change

echo %TEST%> TestAttempt.txt

to

>TestAttempt.txt echo %TEST%

A digit directly before a redirector redirects that device # (0=stdin,1=stdout,2=stderr)

Hence your code reduced to echo which reports the echo status (on or off).

echo(%potentiallyemptyvar% will produce an empty line if potentiallyemptyvar is indeed empty.

Upvotes: 2

Related Questions