I have a program which outputs various results onto a command line console.
How do I save the output to a text file using a StreamReader
or other techniques?
System.Collections.Generic.IEnumerable<String> lines = File.ReadAllLines(@"C:\Test\ntfs8.txt"); foreach (String r in lines.Skip(1)) { String[] token = r.Split(','); String[] datetime = token[0].Split(' '); String timeText = datetime[4]; String actions = token[2]; Console.WriteLine("The time for this array is: " + timeText); Console.WriteLine(token[7]); Console.WriteLine(actions); MacActions(actions); x = 1; Console.WriteLine("================================================"); } if (x == 2) { Console.WriteLine("The selected time does not exist within the log files!"); } System.IO.StreamReader reader = ; string sRes = reader.ReadToEnd(); StreamWriter SW; SW = File.CreateText("C:\\temp\\test.bodyfile"); SW.WriteLine(sRes); SW.Close(); Console.WriteLine("File Created"); reader.Close();
the shortcut is Ctrl + Shift + S ; it allows the output to be saved as a text file, or as HTML including colors!
Saving your workspace is how you save your data within R. Click on the Console window, go to the File menu and select “Save Workspace...”. In another R session, you open this workspace with the “Load Workspace...” command. To save everything that has scrolled past on the Console window, click on the Console window.
Try this example from this article - Demonstrates redirecting the Console output to a file
using System; using System.IO; static public void Main () { FileStream ostrm; StreamWriter writer; TextWriter oldOut = Console.Out; try { ostrm = new FileStream ("./Redirect.txt", FileMode.OpenOrCreate, FileAccess.Write); writer = new StreamWriter (ostrm); } catch (Exception e) { Console.WriteLine ("Cannot open Redirect.txt for writing"); Console.WriteLine (e.Message); return; } Console.SetOut (writer); Console.WriteLine ("This is a line of text"); Console.WriteLine ("Everything written to Console.Write() or"); Console.WriteLine ("Console.WriteLine() will be written to a file"); Console.SetOut (oldOut); writer.Close(); ostrm.Close(); Console.WriteLine ("Done"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With