C#:重定向过程的标准输出已经运行 [英] C#: Redirect Standard Output of a Process that is Already Running
问题描述
我一直有一个很难得到一个子流程的输出(一按我正在通过C#的System.Diagnostics.Process监控黑箱过程内部推出)
I've been having a hard time getting the output of a "sub-process" (one launched internally by a blackbox process that I'm monitoring via c# System.Diagnostics.Process)
我把我的以前的职位的答案给出的建议是:
的此处。还有你可以找到已经经历我的详细信息。
I took the advice given by the answer of my previous post: here. And there you can find the details of what I've been going through.
在这一点上,虽然我能找到由process1.exe催生了SSH进程,我正在监控。我不能输出重定向到我的C#程序,因为它是一个已经运行的进程,并没有直接从C#推出。
At this point, although I'm able to locate the ssh process spawned by process1.exe, that I'm monitoring. I can't redirect the output to my c# program, because it is an "already running process", and wasn't launched directly from C#.
看来,所有你的System.Diagnostics.Process对象上设置的属性,才生效,如果您明确启动从C#应用程序进程;如果一些其他的非托管进程已经推出的过程中,设置此重定向没有任何影响,因为这个过程已经被一些不指定我需要重定向启动。
It seems that, all the properties that you set on a System.Diagnostics.Process object, only take effect if you are explicitly launching that process from your c# application; if some other "unmanaged process" has launched the process, setting this redirection has no effect, because the process has already been launched by something that didn't specify the redirection I need.
有没有什么办法,以重定向已经启动一个进程的输出(通过一个程序,我有没有范围推出的这个过程之前预先指定重定向启动的进程)?
Is there any way to redirect output of a process that has already been launched (a process launched by a program for which I have no scope to pre-specify redirection before this process is launched)?
推荐答案
假设有没有更简单的解决方案,你可以尝试通过CreateRemoteThread的()另一个进程运行一段代码,解释的这里。
Assuming there's no more straightforward solution, you could try to run a piece a code in another process through CreateRemoteThread(), explained here.
这篇关于C#:重定向过程的标准输出已经运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!