Solved

echoimg multiple lines of text

Posted on 2009-07-06
14
249 Views
Last Modified: 2012-05-07
Hi,

I am trying to echo multiple lines into a text fil but it fails everytime it hits a ". Is there anyway to use escape characters with echo,

Here's the code I am trying to echo

SET SMTPSERVER=smtp.xxxx.com
SET MAILPATH=D:\
REM SET MAILUSER=
SET MAILFROM=SQL %COMPUTERNAME%
SET MAILTO=SQLTEAM
rem check if datalist variable exists.
if "%DATALIST%"=="" (
SET MAILSUBJ=SQL Data protector %SERVERNAME% Backup **FAILED**
SET MAILBODY=Backup of %SERVERNAME% started at %STARTTIME% failed:  No Datalist Variable
goto :SendMail
)
rem echo before parse %datalist% > %LOGSERVERNAME%
0
Comment
Question by:chetan1981
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 30

Expert Comment

by:Britt Thompson
ID: 24787515
the echo escape character is "^"
0
 
LVL 30

Expert Comment

by:Britt Thompson
ID: 24787554
You can always copy that to a text file and use "type filename.txt" to display all the lines or echo them to another file.
0
 

Author Comment

by:chetan1981
ID: 24787568
Thanks!!

One more thing..the command prompt appears before every new line..

C:\>SET SMTPSERVER=smtp.xxxx.com
C:\>SET MAILPATH=D:\
C:\>REM SET MAILUSER=


Any way that I can avoid that.

Thanks again


0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 30

Expert Comment

by:Britt Thompson
ID: 24787595
In which case is the command prompt appearing? What's the exact code you're using?
0
 

Author Comment

by:chetan1981
ID: 24787742
echo "SET SMTPSERVER=smtp.xxxx.com
SET MAILPATH=D:\
REM SET MAILUSER=
SET MAILFROM=SQL %COMPUTERNAME%
if ^"%DATALIST%"==^"^" (
" > file.txt


This is what I tried
Thanks
0
 

Author Comment

by:chetan1981
ID: 24787835
I can not copy from a file into a new file as the file does not currently exist on the server and I can just have one file at a time on the server
0
 
LVL 30

Assisted Solution

by:Britt Thompson
Britt Thompson earned 150 total points
ID: 24787961
If you can't do the text file option you'll need to echo each line individually...I've never been able to find a way around this one.


echo SET SMTPSERVER=smtp.xxxx.com> file.txt
echo SET MAILPATH=D:\>> file.txt
echo REM SET MAILUSER=>> file.txt
echo SET MAILFROM=SQL %COMPUTERNAME%>> file.txt
echo if ^"%DATALIST%"==^"^" (>> file.txt
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24788229
You just need to add @echo off at the start for the c:\ bit...
0
 
LVL 30

Expert Comment

by:Britt Thompson
ID: 24788687
That does get rid of the c:\ but it still doesn't allow the echo'ed lines to be inserted into the text file...I'm interested if you know how to do that? Would make my life easier.
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 24789300
Can you provide the example of what you want the text file to look like?
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 24789356
OK. I'll just take what you have in your question literally.

I set the LOGSERVERNAME so I can test it.
@ECHO OFF
Set LOGSERVERNAME=C:\Output.cmd
(
ECHO SET SMTPSERVER=smtp.xxxx.com
ECHO SET MAILPATH=D:\
ECHO REM SET MAILUSER=
ECHO SET MAILFROM=SQL %%COMPUTERNAME%%
ECHO SET MAILTO=SQLTEAM 
ECHO rem check if datalist variable exists.
ECHO if "%%DATALIST%%"=="" ^(
ECHO SET MAILSUBJ=SQL Data protector %%SERVERNAME%% Backup **FAILED**
ECHO SET MAILBODY=Backup of %%SERVERNAME%% started at %%STARTTIME%% failed:  No Datalist Variable
ECHO goto :SendMail
ECHO ^)
ECHO rem echo before parse %%datalist%%
) > %LOGSERVERNAME%

Open in new window

0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 350 total points
ID: 24789375
Oh. Sorry you might have wanted the LOGSERVERNAME as part of the echo.


renazonse:

"That does get rid of the c:\ but it still doesn't allow the echo'ed lines to be inserted into the text file...I'm interested if you know how to do that? Would make my life easier."

Did my answer help this?
@ECHO OFF
(
ECHO SET SMTPSERVER=smtp.xxxx.com
ECHO SET MAILPATH=D:\
ECHO REM SET MAILUSER=
ECHO SET MAILFROM=SQL %%COMPUTERNAME%%
ECHO SET MAILTO=SQLTEAM 
ECHO rem check if datalist variable exists.
ECHO if "%%DATALIST%%"=="" ^(
ECHO SET MAILSUBJ=SQL Data protector %%SERVERNAME%% Backup **FAILED**
ECHO SET MAILBODY=Backup of %%SERVERNAME%% started at %%STARTTIME%% failed:  No Datalist Variable
ECHO goto :SendMail
ECHO ^)
ECHO rem echo before parse %%datalist%% ^> %%LOGSERVERNAME%%
)>C:\output.cmd

Open in new window

0
 
LVL 30

Expert Comment

by:Britt Thompson
ID: 24789438
Much better for me...thanks. I didn't know you could wrap it in parenthesis like that. Nice solution...still not a pretty as a SHELL script echo but better than what I've been doing for sure.

Much obliged.
0
 

Author Comment

by:chetan1981
ID: 24849033
Thanks to both of u...works perfectly.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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