从不相关的进程捕获输出 [英] Capture output from unrelated process

查看:117
本文介绍了从不相关的进程捕获输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,如果它是可以捕捉到Windows上运行的独立过程的输出?

I was just wondering if it is possible to capture the output of a separate process running on windows?

举例来说,如果我有一个控制台应用程序运行时,我可以运行第二个应用程序,表单应用程序,并拥有该应用程序捕获从控制台应用程序的输出,并在文本框中显示呢?

For instance if i have a console app running, could i run a second app, a forms app, and have that app capture the output from the console app and display it in a text box?

推荐答案

您可以这样做:

    Process[] p = Process.GetProcessesByName("myprocess.exe");

    StreamReader sr = new StreamReader(p[0].StandardOutput);

    while (sr.BaseStream.CanRead)
    {
        Console.WriteLine(sr.ReadLine());
    }

这篇关于从不相关的进程捕获输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆