【发布时间】:2011-10-25 01:21:18
【问题描述】:
我有一个 Web 应用程序,我想将命令发送到命令行(命令未知)。这是我使用的方法
public static string ExecuteCommand(string command)
{
String result;
try
{
//Create a new ProcessStartInfo
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
//Settings
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
//Create new Process
System.Diagnostics.Process proc = new System.Diagnostics.Process();
//Set ProcessStartInfo
proc.StartInfo = procStartInfo;
//Start Process
proc.Start();
//Wait to exit
proc.WaitForExit();
//Get Result
result = proc.StandardOutput.ReadToEnd();
//Return
return result;
}
catch
{
}
return null;
}
该命令适用于控制台应用程序,但不适用于 Web 应用程序(返回 null)
public string test = "NOTHING";
protected void Page_Load(object sender, EventArgs e)
{
test = AppCommandHandler.ExecuteCommand("mkdir test2");
}
我做错了什么?我看的每个教程都告诉我使用ProcessStartInfo
编辑我不断收到此错误:
{"StandardOut 未重定向或进程未启动 还没有。”}
【问题讨论】:
标签: c# asp.net web-applications command