Solved

echoimg multiple lines of text

Posted on 2009-07-06
14
250 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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