Question

I have a C# console application that I can run and watch at the console by just c typing:

programName.exe

I also can write this to a file by doing:

programName.exe > log.txt

But, when I do this, I can't view the output as it is happening. I'm force to just view the log file after the entire program has finished.

How can I do both at the same time? I want to see real-time stdout and stderr, but still write to that log file. Is there a way to do this without altering the c# applications code?

Was it helpful?

Solution

If using Windows PowerShell is an option, for you, you can use the Tee-Object command:

programName.exe | tee -file 'log.txt'

This will redirect stdout simultaneously to the console window and log.txt. A workaround to redirect both stdout and stderr is:

programName.exe 2>&1 | tee -file 'log.txt'

You may also find the responses to this similar question helpful

OTHER TIPS

I do not know any existing command can do this.

But you can write a simple new program to copy the stdin and write them to console and file. Hope this can help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top