如何在ASP.NET C#中执行bat文件并对其进行跟踪

如何在ASP.NET C#中执行bat文件并对其进行跟踪,c#,asp.net,shell,process,system.diagnostics,C#,Asp.net,Shell,Process,System.diagnostics,我需要执行一个调用第三方过程的bat文件,但首先我尝试执行一个简单的bat,将输出写入文本文件。 文本文件没有创建,我不能用断点跟踪它,你能帮我吗 System.Diagnostics.Process si = new System.Diagnostics.Process(); si.StartInfo.WorkingDirectory = @"c:\"; si.StartInfo.UseShellExecute = false; si.StartInfo.FileName = "cmd.exe

我需要执行一个调用第三方过程的bat文件,但首先我尝试执行一个简单的bat,将输出写入文本文件。 文本文件没有创建,我不能用断点跟踪它,你能帮我吗

System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.WorkingDirectory = @"c:\";
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = Server.MapPath("Temp/test.bat");
si.StartInfo.CreateNoWindow = true;
si.StartInfo.RedirectStandardInput = true;
si.StartInfo.RedirectStandardOutput = true;
si.StartInfo.RedirectStandardError = true;
si.Start();
//string output = si.StandardOutput.ReadToEnd();
si.Close();
这是bat文件的内容:

echo test > test.txt

最后,我成功了,我只需要改变路径:

                    string path = Server.MapPath("Temp");
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.StartInfo.WorkingDirectory = path;
                    proc.StartInfo.UseShellExecute = false;
                    proc.StartInfo.FileName = PCombine(path, "test.bat");
                    proc.StartInfo.Arguments = String.Format("{0} {1}", PCombine(path, filename), PCombine(path, "new_" + filename));
                    proc.StartInfo.CreateNoWindow = true;
                    proc.StartInfo.RedirectStandardInput = true;
                    proc.StartInfo.RedirectStandardOutput = true;
                    proc.StartInfo.RedirectStandardError = true;
                    proc.Start();
                    proc.WaitForExit();
                    proc.Close();
                    proc.Dispose();

确保您使用的路径是IIS应用程序池用户具有写入权限的路径。