我试图访问命令行并执行命令,然后将输出返回到我的aspx页面。一个很好的例子是在页面加载一个aspx页面并通过Response.Write()返回输出结果。我曾尝试使用下面的代码。当我尝试调试它时,它会运行,但从未完成加载并且不显示输出。 我正在使用C#和.NET Framework 3.5sp1。任何帮助非常感谢。从ASPX页面运行命令行,并返回输出到页面
感谢, 布莱恩
public partial class CommandLine : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.WorkingDirectory = @"c:\";
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = "dir";
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();
Response.Write(output);
}
}
非常感谢!很棒。我实际上使用w/perforce进行交互。 – user32474 2008-10-29 18:54:33