How do you echo a variable name to a file?

October 16, 2010 at 15:45:55
Specs: Windows 7 x64 Pro, Intel Core 2 Duo 2.0 Ghz/4 GB
I am trying to make a batch that will automatically back up one of my save games by copying it to a new folder and copying it to a temp file every five minutes. I am doing this by having a batch first copy the save then make a new batch file through echo and having it do the repetitive copy while the other one starts and waits for the game. I would like the two batch files to communicate and I am trying do do this by having a text file be a variable repository. But when I have the first batch copy the variable name into an if statement to the second batch, it tries to replace it with the value but I haven't set one. I would like to keep the first batch making the second so it is all kept in one file until ran.

My code is very long so here is just the segment
Code:
echo set /p b^<com.txt>>Sub-Saver.bat
echo set a=done>>Sub-Saver.bat
echo if %b%==%a% goto end>>Sub-Saver.bat

Result:
set /p b<com.txt
set a=done
if == goto end


See More: How do you echo a variable name to a file?

Report •


#1
October 16, 2010 at 23:37:09
Try doubling the % symbols e.g. %%b%%

Report •

#2
October 16, 2010 at 23:37:33
echo if %%b%%==%%a%% goto end>>Sub.bat


=====================================
Life is too important to be taken seriously.

M2


Report •

#3
October 16, 2010 at 23:39:06
Hi Wahine,

I guess I'm 24 seconds late.

:(


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
October 17, 2010 at 00:03:21
Hi M2GO. You'll have to learn to type faster.

Report •

#5
October 17, 2010 at 00:13:36
I got a right to be slow. I'm old.


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
October 17, 2010 at 01:34:53
Thank you so much! This did exactly what I wanted, I was staring to think it may be impossible.

Report •

#7
October 17, 2010 at 02:13:47
GTH

I have a bad feeling about BATs running all the time. Not to mention one creating another. Hope all goes well.


=====================================
Life is too important to be taken seriously.

M2


Report •

#8
October 17, 2010 at 21:36:07
This doesn't run all the time it starts the game and waits for it to close the closes it's self.

Report •

Ask Question