Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect the STD-Out of an **existing** process in C#

I can easily start a process with it's STD I/O redirected but how can I redirect the STD I/O of an existing process.

Process process = Process.GetProcessById(_RunningApplication.AttachProcessId);

process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;

string text = process.StandardOutput.ReadToEnd(); //This line blows up.

Exception:

StandardOut has not been redirected or the process hasn't started yet.


Side note: If you know how to do this in C/C++ I'd be happy to re-tag and accept. I just need to know if it's even possible.

like image 395
NTDLS Avatar asked Nov 04 '22 18:11

NTDLS


1 Answers

It doesn't look like it's possible in C#. Looking at possibility in C++.

EDIT: You can use named pipes in C# and that may be a better way to get IPC if that is what you are trying to accomplish.

like image 152
Nate Zaugg Avatar answered Nov 14 '22 21:11

Nate Zaugg