Questions tagged [console.setout]

5 questions
6
votes
4 answers

Console.SetOut to StreamWriter, write to textfile constantly

I'm using the Console.SetOut method to write all my Console.Out.WriteLines to a file, and this works. The only problem is that it only writes everything to the textfile when I close my application instead of it writing whenever a…
3
votes
4 answers

How can I ensure atomicity of a get-and-set operation to redirect Console.Out for logging console output?

I need to intercept the console output stream(s) in order to capture it for a log but still pass things through to the original stream so the application works properly. This obviously means storing the original Console.Out TextWriter before…
Rob Parker
  • 4,078
  • 1
  • 25
  • 26
0
votes
1 answer

System.ObjectDisposedException: 'Cannot write to a closed TextWriter.' Error in SetOut

I'm writing a program that can view all files inside a folder then write the console output to a new txt file but when I run the program after writing 1 line, it produces an error saying System.ObjectDisposedException: 'Cannot write to a closed…
0
votes
1 answer

How to catch %ERRORLEVEL% when running Psexec.exe in C#, save to log file

I am using psexec.exe to install some software on a large amount of computers. I would like to be able to catch the %ERRORLEVEL% (or its c# equivalent) and write them to a TXT file. ( cmd.exe exited on 6440-nbpb00f51w with error code 0.) After…
HoustoneD
  • 63
  • 1
  • 3
  • 15
-2
votes
1 answer

.NET Console.WriteLine() Console.SetOut

I have written a program to go through a fixed file and insert a | where needed, The program works fine and displays in the console correctly. The issue is I cannot get the line from the console to write to a line in the file. All attempts end up…
Arron
  • 25
  • 1