请教个C#中调用现有exe程序的问题

qingqing08 2008-05-07 09:46:25
各位大侠,请教个C#中调用现有exe程序的问题
本人利用单击button,调用现有的***.exe程序,
该程序一般显示为命令行形式,只能通过CMD中启动,单击该程序就一闪而过,消失了
现写的代码如下

private void button1_Click(object sender, EventArgs e)
{
string exe_path = @"F:\";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "***.exe";
process.StartInfo.WorkingDirectory = exe_path;
process.StartInfo.CreateNoWindow = true;
process.Start();
if (process.HasExited)
{
MessageBox.Show("complete");
}

请教各位如何单击后,把***.exe中显示的信息显示到窗口的一个文本框中?
...全文
313 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序的色彩 2008-05-08
  • 打赏
  • 举报
回复
System.IO.StreamReader reader = p.StandardOutput;
截取输出流就好了。
jinjazz 2008-05-07
  • 打赏
  • 举报
回复
using System;
using System.Windows.Forms;

namespace WindowsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

delegate void dReadLine(string strLine);
private void excuteCommand(string strFile, string args, dReadLine onReadLine)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo();
p.StartInfo.FileName = strFile;
p.StartInfo.Arguments = args;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
System.IO.StreamReader reader = p.StandardOutput;//截取输出流
string line = reader.ReadLine();//每次读取一行
while (!reader.EndOfStream)
{
onReadLine(line);
line = reader.ReadLine();
}
p.WaitForExit();
}

private void button1_Click(object sender, EventArgs e)
{
excuteCommand("ipconfig", "", new dReadLine(PrintMessage));
}
private void PrintMessage(string strLine)
{
this.textBox1.Text += strLine + "\r\n";
}
}
}
ldy3881685 2008-05-07
  • 打赏
  • 举报
回复
System.Diagnostics.Process.Start(路径+@".exe ");

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧