在C#中的GUI应用程序中重定向.exe文件输出 [英] Redirection of .exe file output in GUI application in C#

查看:161
本文介绍了在C#中的GUI应用程序中重定向.exe文件输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我使用C#,并且我想执行.exe文件,并且希望重定向命令的输出,因此可以将输出放入字符串变量中.
我在控制台应用程序中尝试以下代码,并且效果很好-命令的输出将在"out"变量中:

Process p = new Process();
//重定向子进程的输出流.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName ="C:\\ dcmdump.exe";
p.StartInfo.Arguments ="C:\\ IMG.dcm";
p.Start();
字符串输出= p.StandardOutput.ReadToEnd();
p.WaitForExit();


但是,当我尝试在简单的GUI应用程序中执行完全相同的代码时,它不起作用-输出"变量将包含一个空字符串:(

可能是什么问题?

非常感谢!

Hello,

I work with C# and I want to execute .exe file and I want to redirect the output of the command, so I could put the output in string variable.
I try the following code in Console application and it works great - the output of the command will be in "out" variable:

Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "C:\\dcmdump.exe";
p.StartInfo.Arguments = "C:\\IMG.dcm";
p.Start();
string out = p.StandardOutput.ReadToEnd();
p.WaitForExit();


But when I try to execute exactly the same code in a simple GUI application it doesn''t work - the "out" variable will contain an empty string :(

What can be the problem?

Thanks a lot!

推荐答案

提示的名称是: G raphical U ser I 界面
不是文本,而是图形.
您只是期望捕获什么?
按钮上的文字?
菜单栏?

不,它不能那样工作.
The clue is in the name: Graphical User Interface
Not Text, but graphics.
Just what did you expect to capture?
The text on buttons?
A menu bar?

No, it doesn''t work like that.


这篇关于在C#中的GUI应用程序中重定向.exe文件输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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