各位大侠,请教个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中显示的信息显示到窗口的一个文本框中?
本人利用单击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中显示的信息显示到窗口的一个文本框中?
解决方案 »
- C#刚入门 寻找KeyPress事件求助
- 如何让C#做出来的安装包不被杀毒软件删除
- 数据库连接小程序,运行出错,提示“未将对象引用到示例”,错在哪?
- 传值
- C#中 通过 OLedb 从2007 的Excel文件中读取数据的连接字符串是什么啊
- 关于Windows Workflow Foundation的请教!小弟先感谢前辈了!
- 如何更新数据表里头的ID编号?
- 如何写连接类更为合适?
- EXCEL导入SQL
- java技术高手联盟(12309569)和c#联谊会(11019078)挺不错的
- 用XmlReader循环读取xml中的节点
- 遍历一个实体对象,该实体对象是一个树形,并且获取所有的值类型,若是引用类型继续向下递归,如何实现?
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";
}
}
}
截取输出流就好了。