Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Within a batch file, echo the literal string %something% to another file, rather than the variable expanding

Posted on 2009-05-20
10
Medium Priority
?
1,181 Views
Last Modified: 2012-05-07
Hi,

From a batch file, I was wondering how I can echo the literal string %something% to a file, rather than the variable expanding and the value of the variable being echoed to the file.

Thanks
Matthew
0
Comment
Question by:Matthew Millers
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 14

Expert Comment

by:yehudaha
ID: 24431246
like this ?

echo %variable% >> log.txt
0
 
LVL 16

Author Comment

by:Matthew Millers
ID: 24431385
Not really, that would either put nothing in the output file or expand the variable %variable% and put the current value into the output file.

What i actually want to do is literally output %variable% into the output file.

So....
echo %variable% >> log.txt

log.txt would contain
%variable%

Rather than
ValueofVariable
0
 
LVL 16

Author Comment

by:Matthew Millers
ID: 24431437
Hi,

Worked it out.

^%%VARIABLE^%%  >> textfile

SO textfile contains
%VARIABLE%

Thanks for your efforts.

Matthew
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:yehudaha
ID: 24431467
no problem
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 24431478
You actually only need double pecent signs:
echo %%variable%% >> log.txt
The caret is required to echo/escape other special characters, like < > | ( ) &
In addition, I'd recommend to put the echo at the beginning, it prevents the lines in the text file ending with a space:
>>"log.txt" echo %%variable%%
0
 
LVL 16

Author Comment

by:Matthew Millers
ID: 24431511
HI,

I tried the %%variable%% and it actually placed the %%variable%% into the output file!

THanks very much for the echo advice, I will use that from now on.

Matthew
0
 
LVL 85

Expert Comment

by:oBdA
ID: 24431783
Did you try that on the command line?
There is a slightly different behavior between echo in the command window and a batch script.
In a script, you normally need two percent signs to echo one.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24434542
what's your purpose for doing this?
0
 
LVL 16

Author Comment

by:Matthew Millers
ID: 24434656
Hi,

I was writing a script where I could parse a number of disk GUIDs and call the diskshadow program to snap the volumes off for backup purposes. The diskshadow program does not recognise system variables as it uses its own aliases.

Part of the command sequence is to create a alias using %alias%, hence the question.

I have finished the script now anyway, so all good!

Thanks
Matthew
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24434689
makes sense. you seem to know what you're doing.... glad y ou got there!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question