Solved

How To Output a Message to Both a File and Console

Posted on 2008-06-09
3
241 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
Comment Utility
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
Comment Utility
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
Comment Utility
B grade ?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This is my 3rd article on SCCM in recent weeks, the 1st (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html) dealing with installat…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

12 Experts available now in Live!

Get 1:1 Help Now