我的代码包含: 我想忽略与批处理文件的输出一起显示的目录路径(例如:c:\ users \ visual studio 2012 \ projects \ wpf sample \ bin \ Debug>)
{
Process proc = new Process();
proc.StartInfo.FileName = "C:\\test.bat"
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
proc.OutputDataReceived += proc_OutputDataReceived;
proc.Start();
proc.BeginOutputReadLine();
}
void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
this.Dispatcher.Invoke((Action)(() =>
{
w.tb1.Text = w.tb1.Text + "\n" + e.Data;
w.Show();
}));
}
我的test.dat文件包含:
Hello
目录创建D:\ MyDir