Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

echoimg multiple lines of text

Posted on 2009-07-06
14
Medium Priority
?
257 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: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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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 …
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

824 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