0

I want to capture the output of a console application in my C# code, but without affecting the output of the program itself.

I know how to launch a console application and catch its output (it's described here). But all of the solutions there set RedirectStandardOutput=true, which means that the window being opened just stays black. This is of course bad if the window would show progress or require user input. Is there a way to capture the output without changing RedirectStandardOutput to true?

EDIT Here it says "By setting RedirectStandardOutput to true to redirect the StandardOutput stream, you can manipulate or suppress the output of a process. For example, you can filter the text, format it differently, or write the output to both the console and a designated log file.". But they don't explain how filtering would work. Can I write to the console of another process?

EDIT2 The linked question doesn't help me, it seems. Since my own application is a WPF GUI app, I can't just write to the console. I need to write to the console of the target app, not my own.

PMF
  • 14,535
  • 3
  • 23
  • 49
  • Does this answer your question? [Capture standard output and still display it in the console window](https://stackoverflow.com/questions/786726/capture-standard-output-and-still-display-it-in-the-console-window) – Klaus Gütter Mar 04 '22 at 10:44
  • @KlausGütter Unfortunately not. My own process is a WPF GUI application, so running `Console.Write(...)` with the received data doesn't work. – PMF Mar 04 '22 at 10:49
  • Is the console application under your control, i.e. can you make changes to it to explicitely support this scenario? – Klaus Gütter Mar 04 '22 at 10:56
  • @KlausGütter Yes, it is. But changing all output from that application somehow would be a bit of a pain. And it launches further console tools I don't have control over. – PMF Mar 04 '22 at 10:58
  • I found that the tool I was going to call already had the logging capability (that's what I was trying to do) almost implemented, so I went down that path. – PMF Mar 07 '22 at 08:25

0 Answers0