MSFN Forum: .cmd file: echo escape character ^ appears in output - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

.cmd file: echo escape character ^ appears in output Batch File Guru Needed Rate Topic: -----

#1 User is offline   daddydave 

  • Member
  • PipPip
  • Group: Members
  • Posts: 102
  • Joined: 08-December 06
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 24 January 2007 - 11:15 AM

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.

This post has been edited by daddydave: 24 January 2007 - 11:17 AM



#2 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 24 January 2007 - 11:54 AM

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


#3 User is offline   daddydave 

  • Member
  • PipPip
  • Group: Members
  • Posts: 102
  • Joined: 08-December 06
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 24 January 2007 - 12:04 PM

Thanks, Yzöwl, that fixes it! :thumbup

And you're right, I hadn't considered that running it from the console was distorting my output.

This post has been edited by daddydave: 24 January 2007 - 12:05 PM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy