-1

I would like, if possible, an example on how to, using a c# windows form, save the data in the debug window to a file, or to use it directly.

I am calling a jtag program through a CMD prompt window and I need to be able to read back and process the response.

As I have noticed there are some examples of this function already but they all seem to save predefined data using WriteLine text. I do not need to write any specific data, just read back and save or process the data that returns from the jtag command line.

Any help here would be greatly appreciated.

siod
  • 1
  • 2
  • 4
    Possible duplicate of [Writing C# debug output to .txt file](https://stackoverflow.com/questions/7926577/writing-c-sharp-debug-output-to-txt-file) – Isma May 24 '18 at 11:38

1 Answers1

0

You can try setting the console's output to a TextWritter that you declare in your application. Something like this:

using (var writer = new StringWriter())
{
    Console.SetOut(writer);

    Console.WriteLine("Hello");
    Console.WriteLine("World");

    var writtenText = writer.ToString();
}

As soon as you finish writing to the console, the TextWritter will have all those values... Then you can parse it.

Edit (thanks to @Ron Beyer)

Something similar is suggested in this post, where they essentially launch an external process and read the contents of what is written into the output stream.

Martin
  • 475
  • 4
  • 14
  • From the post: *". I do not need to write any specific data, just read back and save or process the data that returns from the jtag command line."* – Ron Beyer May 24 '18 at 12:16
  • The Console.WriteLine calls were just an example to show that the writer will have the contents of what was put in the console... – Martin May 24 '18 at 12:26
  • I think you are misunderstanding what the OP wants, they want to parse the output from an external tool, not what their own application writes to the console. – Ron Beyer May 24 '18 at 12:30
  • Yes, that is exactly right. I need to parse the output from an external tool, not what the application writes to the console. For example, I will need to ping a device and check to see if the device responds. Is there a way to read back the ping data generated in the command prompt window? – siod May 29 '18 at 15:14