So say I run my program:
Process proc = new Process();
proc.StartInfo.FileName = Path.GetDirectoryName(Application.ExecutablePath)
+ @"\Console.exe";
proc.Start();
And then wish to output my console stream to this application, how would I go about doing so?
So say I have:
Console.WriteLine("HEY!");
I want that to show up in program that I ran’s console. I know I have to redirect the output using
Console.SetOut(TextWriter);
But I have no idea how I would go about making it write to the other program.
I can see how I could do it if I were running my main program from Console.exe using RedirectStandardInput.. but that doesn’t really help 😛
RedirectStandardInputmakes Console.exe take its input from a stream which you can access in the main program. You can either write directly to that stream, or use SetOut to redirect console output there…EDIT
It’s possible that Console.exe doesn’t cope well with having data piped into it rather than entered interactively. You could check this from the command line with something like
If that doesn’t do what you expect, redirecting your program’s output won’t either. To test your program without worrying about the target program, you could try
If that displays the text that you write to it, then the problem is on the receiving end.