Console.write line
-
Guys, I have a comnosle application that runs as a job in the middle of the night and displays the info via console.write line. I have a question: Is there any way to eather retrive what is written in the screen and write to a file or is there anyway to dump the content of the screen to a file without having to make many modification where ever I have console.write line Please advice guys! Thanks a lot!
-
Guys, I have a comnosle application that runs as a job in the middle of the night and displays the info via console.write line. I have a question: Is there any way to eather retrive what is written in the screen and write to a file or is there anyway to dump the content of the screen to a file without having to make many modification where ever I have console.write line Please advice guys! Thanks a lot!
-
Console.SetOut[^] You can set the output to any stream (eg a filestream).
I tried this at the very end of main thread but nothing got written //here call a method that does console.write lines //when done do the code below and file is empty FileStream fs = new FileStream(@"c:\out1.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); Console.SetOut(sw); sw.Close(); fs.Close(); Please advice with some more details
-
Guys, I have a comnosle application that runs as a job in the middle of the night and displays the info via console.write line. I have a question: Is there any way to eather retrive what is written in the screen and write to a file or is there anyway to dump the content of the screen to a file without having to make many modification where ever I have console.write line Please advice guys! Thanks a lot!
You don't have to change anything at all in the code. You can pipe the output from the program into a file when you run it. To send the output to the file "app.log":
TheApplication.exe > app.log
To apppend the output (keeping previous results):TheApplication.exe >> app.log
If you can't add this from where you run the application, create a batch file (.bat) that contains a line as I showed above, and start the batch file instead of the application.Despite everything, the person most likely to be fooling you next is yourself.
-
You don't have to change anything at all in the code. You can pipe the output from the program into a file when you run it. To send the output to the file "app.log":
TheApplication.exe > app.log
To apppend the output (keeping previous results):TheApplication.exe >> app.log
If you can't add this from where you run the application, create a batch file (.bat) that contains a line as I showed above, and start the batch file instead of the application.Despite everything, the person most likely to be fooling you next is yourself.
-
Neither, it's a shell/OS feature. Did you actually try it?
Cheers, Vıkram.
"You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.
-
Neither, it's a shell/OS feature. Did you actually try it?
Cheers, Vıkram.
"You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.
-
I tried this at the very end of main thread but nothing got written //here call a method that does console.write lines //when done do the code below and file is empty FileStream fs = new FileStream(@"c:\out1.txt", FileMode.Create); StreamWriter sw = new StreamWriter(fs); Console.SetOut(sw); sw.Close(); fs.Close(); Please advice with some more details
-
-
I am sorry but I don't get what neds to happen. can u send me a bit code like console.write line and out put it? please help me if u can otherwise I would have to collect all console.write line in a string builder.
Just start your program from a command prompt (cmd.exe), and add " > somfile.txt" after the program name, and the output of the program is sent to the file. This is built into the command shell, and you can for example send a directory listing to a file:
dir c:\users\nesfrank\documents > myfiles.txt
Despite everything, the person most likely to be fooling you next is yourself.
-
I am sorry but I don't get what neds to happen. can u send me a bit code like console.write line and out put it? please help me if u can otherwise I would have to collect all console.write line in a string builder.
There is NO code to be written. Your app (let's call it Foo.exe) has several Console.WriteLine() statements which write to the console, and you want them to be written to a file (let's call it AppLog.txt). Right now, this is how you would invoke your app:
C:\>Foo.exe
Simply change that to
C:\>Foo.exe > AppLog.txt
If you want the app to append to the file rather than overwrite, use
C:\>Foo.exe >> AppLog.txt
Obviously, you will have to use the correct path, etc.
Cheers, Vıkram.
"You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.
-
here is my code class utility { [STAThread] static void Main(string[] args) { ProcessRecords(); //here I placed the code for redirecting to output as above but it did not work. The function ProcessRecords does have some console.writeline statements }
nesfrank wrote:
here I placed the code for redirecting to output as above but it did not work. The function ProcessRecords does have some console.writeline statements
Except the Console.WriteLine() statements have already been written to the console :doh: You must do it before you actually do anything else. I suggest you move it to the beginning of Main().
Cheers, Vıkram.
"You idiot British surprise me that your generators which grew up after Mid 50s had no brain at all." - Adnan Siddiqi.
-
Guys, I have a comnosle application that runs as a job in the middle of the night and displays the info via console.write line. I have a question: Is there any way to eather retrive what is written in the screen and write to a file or is there anyway to dump the content of the screen to a file without having to make many modification where ever I have console.write line Please advice guys! Thanks a lot!
Additionally to what the others already said, there's also a slightly more advanced, yet more flexible solution: log4net[^] It has some nice features: - you can specify where the log messages should go (like to the console, to a file, via mail and much more) - you can add a custom format to your log messages (like a timestamp) - you can specify the type of the log message, like Info, Warning, Error, Debug and much more regards