Solved

How To Output a Message to Both a File and Console

Posted on 2008-06-09
3
244 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

On a regular basis I get questions about slow RDP performance, RDP connection problems, strange errors and even BSOD, remote computers freezing or restarting after initiation of a remote session. In a lot of this cases the quick solutions made b…
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 here: http://www.experts-exchang…

809 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