Solved

echoimg multiple lines of text

Posted on 2009-07-06
14
247 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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