如何用C#获取DOS下的程序出错信息!

来源:百度知道 编辑:UC知道 时间:2024/06/10 03:16:36
如执行命令:
msgunfmt.exe d:\english.mo -o d:\english.po
执行结果是:
msgunfmt.exe: error while opening "d:\english.mo" for reading: No such file or directory

如何去捕获这个信息呢!就是捕获:msgunfmt.exe: error while opening "d:\english.mo" for reading: No such file or directory

private void button1_Click(object sender, System.EventArgs e)
{//获取操作系统的版本信息
if (this.textBox2.Text.Trim().Equals(""))
{
MessageBox.Show("请输入命令!");
return;
}
string cmdtext = this.textBox2.Text.Trim();
Process MyProcess= new Process();
//设定程序名
MyProcess.StartInfo.FileName = "cmd.exe";
//关闭Shell的使用
MyProcess.StartInfo.UseShellExecute = false;
//重定向标准输入
MyProcess.StartInfo.RedirectStandardInput = true;
//重定向标准输出
MyProcess.StartInfo.RedirectStandardOutput = true;
//重定向错误输出
MyProcess.StartInfo.RedirectStandardError = true;
//设置不显示窗口
MyProcess.StartInfo.CreateNoWindow = true;
//执行VER命令
MyProcess.Start();
MyProcess.StandardInput.WriteLine(cmdtext);
MyProcess.StandardInput.WriteLine("exit");
//