Echoing variables into text documents

July 25, 2010 at 13:05:02
Specs: Windows 7
For some reason, when I run any code along these lines:

SET Variable=Hello
ECHO %Variable%>filename.txt

It creates the file, but what is echoed into the file is just "ECHO is off" or "ECHO is on" depending on whether echoing is on or off.

Does anybody know why this is?

EDIT: This is my real code, and I've modified it from when this topic was posted. Now nothing is echoed into the file, and it's contents are left blank.


IF EXIST NextFile.txt GOTO Continue
SET FileNumber=1


Set /p Input=""
ECHO %Input%>%FileNumber%.txt
SET /a FileNumber +=1
ECHO %FileNumber%>NextFile.txt
GOTO Start


SET /p FileNumber= <NextFile.txt
GOTO Start

See More: Echoing variables into text documents

Report •

July 25, 2010 at 14:08:02
My edited version that works:

set variable=Hello
echo %variable%>test123abc.txt

Make sure you don't use caps when typeing the set, echo and the variable names. Also give the text file a name. Hope I helped!

Report •

July 25, 2010 at 15:10:49
Variables are case sensitive, so as long as the set and echo are the same (Variable and Variable) it won't make a difference.

in my first example, filename.txt would be set as the name.

See my second example for my real script.

Report •

July 25, 2010 at 15:15:23
Solved. A user on another forum helped me out with the solution.

Escaping the variable with a caret worked perfectly

ECHO ^%FileNumber%>NextFile.txt

Thanks for your help though.

Report •

Related Solutions

Ask Question