Jump to content

.cmd file: echo escape character ^ appears in output


daddydave

Recommended Posts

I'm trying to echo literal > characters and % characters, and I understand I can escape them with ^ characters, but for some reason the ^ characters appear in the output also. Yet if I remove them, the %TMP% variable is evaluated immediately. In other words the output I want, strangely enough, is

"UninstallString"="cmd /c echo Windows Registry Editor Version 5.00>%TMP%\BlahBlah.reg

I am not trying to create BlahBlah.reg at this time, I am echoing to screen what will eventually be echoed to a different reg file to be merged with the Registry so that BlahBlah.reg can be created at a later time. The syntax is off a bit for the registry, but right now I am just worried about the syntax for the .cmd file

What I get is:

C:\>@echo "UninstallString"="cmd /c echo Windows Registry Editor Version 5.00^>^
%TMP^%\BlahBlah.reg
"UninstallString"="cmd /c echo Windows Registry Editor Version 5.00^>^%TMP^%\Bla
hBlah.reg

C:\>@echo "UninstallString"="cmd /c echo Windows Registry Editor Version 5.00>^%
TMP^%\BlahBlah.reg
"UninstallString"="cmd /c echo Windows Registry Editor Version 5.00>^%TMP^%\Blah
Blah.reg

C:\>@echo "UninstallString"="cmd /c echo Windows Registry Editor Version 5.00>%T
MP%\BlahBlah.reg
"UninstallString"="cmd /c echo Windows Registry Editor Version 5.00>C:\DOCUME~1\
ADMINI~1\LOCALS~1\Temp\BlahBlah.reg

See how the ^ echoes in the output even though I am just using it to keep %TMP% from evaluating during the run of the batch file as it does in the last example above.

Edited by daddydave
Link to comment
Share on other sites


One problem is that your outputting from the console and not a batch, you're testing for a batch run so use a batch for the testing!

Also the escape character for the percent is another percent:

Since you missed a double quote from your examples, I will give you a couple of solutions just in case I've guessed incorrectly!

@ECHO/"UninstallString"="%%COMSPEC%% /c ECHO/Windows Registry Editor Version 5.00 >%%TMP%%\BlahBlah.reg"

@ECHO/"UninstallString"="%%COMSPEC%% /c ECHO/Windows Registry Editor Version 5.00"^>%%TMP%%\BlahBlah.reg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...