Solved

How To Output a Message to Both a File and Console

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

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.

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 here: http://www.experts-exchang…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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