命令行工具的GUI,读取所有进程的输出 [英] GUI for command line tool, reading output of all processes

查看:135
本文介绍了命令行工具的GUI,读取所有进程的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

首先,如果我的英语不好,请问我不是母语人士.

让我先描述一下我要做什么:
我想为我自己没有编写的命令行工具创建GUI.

到目前为止,我能够使用所需的参数启动该工具并捕获其输出流以将其写入文本框.我是在BackgroundWorker中进行的.

但是现在我遇到了以下问题:
此命令行工具控制其他命令行工具(rtmpdump和ffmpeg等)来处理某些数据.如果我在Windows Shell中手动打开该工具,则可以看到该工具本身的输出,并直接跟随外部工具的输出...

在我想要的GUI应用程序中,只要实际的命令行工具的输出结束,输出就会中断,并且由它触发的工具的输出也应该可见.基于创建的文件,我仍然可以看到外部工具仍然在后台运行,但是BackgroundWorker完成了,因此我无法继续分析输出流.

这是我用来读取流的内容:

Hi everybody!

First of all, please excuse me if my English is not perfect, I''m not a native speaker.

Let me first describe what I''m up to:
I want to create a GUI for a command line tool which I have not written by myself.

I got so far to be able to launch the tool with desired parameters and catch its output stream to write it to a text box. I do this in a BackgroundWorker.

But now I got the following problem:
This command line tool controls other command line tools (rtmpdump and ffmpeg among others) to process certain data. If I open the tool manually in the Windows shell I can see the output of the tool itself, directly followerd by the output of the external tools...

In my wannabe GUI app, the output breaks as soon as the output of the actual command line tool ends and the output of the tools triggerd by it should be visible. Based on the files that are created, I can see that the external tools continue to run in the background nevertheless, but the BackgroundWorker finishes and I can not go on analysing the output stream.

This is what I use for reading out the stream:

while (! process.StandardOutput.EndOfStream)



因此,只要命令行工具运行其他工具,或者简而言之,就可以到达EndOfStream:我只能读取初始进程的输出流,而不能读取由它触发的输出流.

我不敢相信C#不可能做到这一点...我认为必须有一种捕获控制台的方法,就像我在cmd中手动打开该工具一样.

到这个重要的细节为止,这使我无法继续进行整个GUI项目,我已经能够从docs或通过Google获得任何信息.但是现在我真的被卡住了.有人有主意吗?

提前谢谢!

亲切的问候
康斯坦丁

PS:即使设置当前工作目录的StartInfo.WorkingDirectory也没有达到预期的效果.



So EndOfStream is reached as soon as the commandline tool runs the other tools, or in a nutshell: I can only read the output stream of the initial process, but not of those triggered by it.

I can''t believe this should not be possible with C#... I think there MUST be a way to capture the console just like I was opening the tool manually in the cmd.

Up to this important detail, that stops me from proceeding with the whole GUI project, I have been able to acquire any information from docs or via Google. But now I''m realy stuck. Does anyone have an idea?

Thank you in advance!

Kind regards
Constantin

PS: Even setting StartInfo.WorkingDirectory of the current working directory did not have the desired effect.

推荐答案

我正在考虑一个解决方案,但是不优雅,我什至不确定它是否会起作用.

您可以尝试使用ManagementEventWatcher通知流程创建,然后获取您感兴趣的流程以重定向其标准输出...是的,不是我所说的那么优雅:(

例如,此链接说明了如何执行此操作:
http://codelog.blogial.com/2009/06/25/managementeventwatcher-in-c / [^ ]

如果事件成功了,您可能会被异步通知,即:该过程可能会在收到通知之前开始,并在有机会重定向其标准输出之前立即开始运行(然后您将错过第一行输出). ..)
I''m thinking of a solution, but it''s not elegant and I''m even not sure if it will work.

You may try to use ManagementEventWatcher to get notified of process creation, then get the process you are interested in to redirect its standard output... yes, not very elegant as I said :(

For example, this link tells how to do this:
http://codelog.blogial.com/2009/06/25/managementeventwatcher-in-c/[^]

And event if it works, you will probably be notified asynchronously, that is: the process will probably start before you get notified and start to run immediately before you get a chance to redirect its standard ouput (you will then miss the first outputed lines...)


这篇关于命令行工具的GUI,读取所有进程的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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