7

I am in a small pinch :)

I found a very wierd behaviour and i cannot figure out what could be the cause of it.

It is related to console Logging in C# Visual studio 2008

For example, a normal behaviour of command line is :

1) If i use the "dir" command i see the contents of the directory

2) If i use "dir > 1.txt" i get the contents of the directory in the 1.txt file.

so this is the normal behaviour and it works. Now back to my problem.

In the c# application i am using, i have a list of tests and i want to list them when i use my application from command line. so i have:

Console.WriteLine("Start running " + sn);

The outcome when i run the application normally is: (The command i send)

Application.exe -run 1.test,2.test,3.test

Output:

Start running 1.test
Start running 2.test
Start running 3.test

but if i use this command:

Application.exe -run 1.test,2.test,3.test > 1.txt

The three Start running commands disappear from the stdout but the 1.txt is BLANK.

I have no idea where the response goes, i have no way of logging the response, but i can see it visually. But when i redirect STDOUT to a log neither it exists visually nor in the log.

Anyone have any idea?

1
  • You may have to wrap with cmd.exe: cmd.exe "Application.exe -run args" > 1.txt. Commented May 28, 2013 at 11:49

1 Answer 1

19

The output to file is buffered. In the worst case the content will be saved after the application finishes. To force buffer flush, you may call:

Console.Out.Flush();
Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me a big time! WriteLine used to fill the whole buffer and the content never showed up in my console. Once I used this it started working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.