Solved

echoimg multiple lines of text

Posted on 2009-07-06
14
246 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
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 30

Expert Comment

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

Expert Comment

by:renazonse
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
 
LVL 30

Expert Comment

by:renazonse
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:renazonse
renazonse 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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:renazonse
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:renazonse
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now