如何在使用c#执行bat文件时忽略输出中的目录路径?

时间:2015-12-27 14:33:52

标签: c# batch-file

我的代码包含: 我想忽略与批处理文件的输出一起显示的目录路径(例如: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

enter image description here

0 个答案:

没有答案