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.



Recommended Answers

All 3 Replies

In unix-land, this would be a doddle.

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.

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.



Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.