User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 402,044 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,451 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 700 | Replies: 3
Reply
Join Date: Mar 2004
Location: Brisbane
Posts: 632
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Rep Power: 7
Solved Threads: 6
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

.bat - Direct stdout to console AND file

  #1  
Jul 22nd, 2008
Hi guys,

Basically what I want to do is run a series of commands in my batch file, and display stdout to screen as well as saving it in a file. So to set the context..

::To output to helloworld.txt
Echo hello world! > helloworld.txt

::To output to console
Echo hello world! > CON

What I’d like to do is have the output of a single command directed to both. As a workaround I’ve got something which will output to a file, and then copy the contents of the file to console.

::Output to file then copy file contents to console
echo Hello World! >test.txt
copy test.txt con > nul

This isn’t ideal since I’d like for the user to see the activity in the console as the batch file is executing commands, rather than in a big batch at the end.

Cheers,

Anthony
Formerly known as Slade.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,393
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 21
Solved Threads: 385
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: .bat - Direct stdout to console AND file

  #2  
Jul 22nd, 2008
In unix-land, this would be a doddle.
http://www.rootr.net/man/man/tee/1

If you have cygwin installed, then you can just use the 'tee' provided in your cygwin bin directory.

Though if you search long enough, you might find a native Win32 implementation as well.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Mar 2004
Location: Brisbane
Posts: 632
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Rep Power: 7
Solved Threads: 6
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: .bat - Direct stdout to console AND file

  #3  
Jul 22nd, 2008
Hi Salem,

Thanks for your reply. The problem is that it kind of has to be native to windows since these are scripts that will be run on other peoples machines who may not have cygwin. I'll keep digging around and see if I can figure this one out. Will keep you all posted.

Actually on this note (but on a tanget to the topic), I have another script which I use to generate C# code documentation using doxygen. If someone doesn't have doxygen clearly this script will not work. I figure one potential way around it though might be to package the doxygen exe with the scripts (I guess this would work for the tee suggestion as well) - but I'm not sure licensing would really permit that. I haven't looked into it myself in depth yet, but would anybody know off hand if the GNU General Public License allows for this?

Permission to use, copy, modify, and distribute this software and its documentation under the terms of the GNU General Public License is hereby granted.

To me that sounds like a yes, but I could be mistaken.

Cheers,

Anthony
Formerly known as Slade.
Reply With Quote  
Join Date: Oct 2007
Posts: 267
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: .bat - Direct stdout to console AND file

  #4  
Jul 22nd, 2008
Hey There,

Here's a link to a win32 tee emulator:

http://www.csc.calpoly.edu/~bfriesen.../console.shtml

Otherwise, if you can somehow manage to do this with robocopy, it's the only dos command I know that has a /TEE option

Best of luck,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 11:31 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC