开发者

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 thi开发者_StackOverflow中文版s in C/C++ I'd be happy to re-tag and accept. I just need to know if it's even possible.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜