【发布时间】:2018-04-16 16:07:57
【问题描述】:
我需要执行一个调用第三方程序的 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
【问题讨论】:
-
确保您使用的是 IIS 应用程序池用户拥有写入权限的路径。
标签: c# asp.net shell process system.diagnostics