echo the "&" symbol to text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
GRock84
Posts: 2
Joined: 21 Sep 2011 12:24

echo the "&" symbol to text file

#1 Post by GRock84 » 27 Sep 2011 12:56

ive have been working at this for several hours now and am stuck.
how in the **** do you echo the "&" symbol to text file? I am using a batch file to copy code to a text file and save it as a .vbs script.
i have:
echo navOpenInBackgroundTab = &h1000>>loginstart.vbs

echo set oIE = CreateObject("InternetExplorer.Application")>>loginstart.vbs

echo oIE.Navigate2 "http://blogs.msdn.com">>loginstart.vbs

echo oIE.Navigate2 "http://blogs.msdn.com/tonyschr",>>loginstart.vbs

echo navOpenInBackgroundTab>>loginstart.vbs

echo oIE.Navigate2 "http://blogs.msdn.com/oldnewthing",>>loginstart.vbs

echo navOpenInBackgroundTab>>loginstart.vbs

echo oIE.Navigate2 "http://blogs.msdn.com/ericlippert",>>loginstart.vbs

echo navOpenInBackgroundTab>>loginstart.vbs

echo oIE.Visible = true>>loginstart.vbs

everything else copies to the "loginstart.vbs", except "navOpenInBackgroundTab = &h1000". I have found that it is due to the "&" symbol. I have tried wrapping that line in quotations. It works, however, it copies the quotations to the file as well, thus rendering the file dysfunctional. how can I successfully copy that symbol without any additional text appearing in the file?

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: echo the "&" symbol to text file

#2 Post by dbenham » 27 Sep 2011 13:10

You will run into similar problems with additional special characters such as > < | ^

The solution is simple - the special characters need to be escaped using ^

Code: Select all

echo navOpenInBackgroundTab = ^&h1000>>loginstart.vbs

Dave Benham

GRock84
Posts: 2
Joined: 21 Sep 2011 12:24

Re: echo the "&" symbol to text file

#3 Post by GRock84 » 27 Sep 2011 13:26

Dude you're my hero! Thanks a lot!

Post Reply