Solved

How To Output a Message to Both a File and Console

Posted on 2008-06-09
3
243 Views
Last Modified: 2008-06-12
Hello,

In a DOS\Console batch file I need to output all information (standard output and error output) to both the screen AND a log type file.  Ideally I Do NOT want to use two lines every time I need to output a message (one to screen and one to file - yuk).  Here is an example output line:

set MYFILE=c:\temp\myfile.log
set FILE_TYPE=Export
echo %time% - Transferring %FILE_TYPE%

I know I can append this to a file using:
echo %time% - Transferring %FILE_TYPE% >> %MYFILE%

OR even

echo %time% - Transferring %FILE_TYPE% >> %MYFILE% 2>&1

My problem is if the above is used I do not get any screen output.  I feel I am close.

What can you suggestion?

Thanks,

Michael4606



When I do this I cannot
0
Comment
Question by:michael4606
  • 2
3 Comments
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 60 total points
ID: 21744498
You'll need a tool like tee.exe (I believe you can get it from here: http://www.weihenstephan.de/~syring/win32/UnxUtilsDist.html)
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 65 total points
ID: 21746652
You can cheat a little too if you are unable to add tools such as tee.exe or don't have them to hand, i.e.

echo %time% - Transferring %FILE_TYPE% >> %MYFILE% 2>&1 & type %myfile%

but that isn't so handy when appending to a file like you are.... you end up with:

echo %time% - Transferring %FILE_TYPE% > %tempfile% 2>&1 & type %tempfile% & type %tempfile%>>%myfile%

and you might aswell use two lines.  Can come in handy sometimes though.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 21773076
B grade ?
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found listed in my profile here: http:…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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