我試圖訪問命令行並執行命令,然後將輸出返回到我的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