我有一个cmd命令来启动/停止服务器/窗口中的应用程序池,它可以工作:
我的问题是同样的代码在c#中不起作用,代码没有返回错误或信息。 C#代码:
public static string StopAppPoolCmd
{
get { return "cd %SYSTEMROOT%/System32/inetsrv & appcmd stop apppool /apppool.name:\"{0}\""; }
}
public static string StartAppPoolCmd
{
get { return "cd %SYSTEMROOT%/System32/inetsrv & appcmd start apppool /apppool.name:\"{0}\""; }
}
// Run Commands
var cmd = new System.Diagnostics.Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
/* execute "dir" */
cmd.StandardInput.WriteLine(string.Format(start ? StartAppPoolCmd : StopAppPoolCmd, serviceName));
//flush object
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
//
// OUTPUT
var result = Tools.CleanShellOutput(cmd.StandardOutput.ReadToEnd());
Console.WriteLine(result);