Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How To Output a Message to Both a File and Console

Posted on 2008-06-09
3
Medium Priority
?
249 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
[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
  • 2
3 Comments
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 180 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 195 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

715 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