Lonnie Best
Lonnie Best

Reputation: 11364

How Can I View the Console RealTime While Also Outputing stdout and stderr to a File

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?

Upvotes: 2

Views: 739

Answers (2)

drf
drf

Reputation: 8699

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

Upvotes: 2

Coofucoo
Coofucoo

Reputation: 119

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.

Upvotes: 1

Related Questions