C# 使用C启用RabbitMQ管理插件#
我一直在尝试使用C代码启用RabbitMQ管理插件 通过使用以下代码,我成功地使用c#安装了RabbitMQ服务器C# 使用C启用RabbitMQ管理插件#,c#,powershell,rabbitmq,cmdlets,rabbitmq-management,C#,Powershell,Rabbitmq,Cmdlets,Rabbitmq Management,我一直在尝试使用C代码启用RabbitMQ管理插件 通过使用以下代码,我成功地使用c#安装了RabbitMQ服务器 RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
Pipeline pipeline = runspace.CreatePipeline();
Command myCommand = new Command("Start-Process");
CommandParameter testParam = new CommandParameter("FilePath", @"C:\Users\saadp\Desktop\Dependencies\rabbitmq-server-3.8.3.exe");
CommandParameter testParam2 = new CommandParameter("ArgumentList", new string[] { "/S" });
CommandParameter testParam3 = new CommandParameter("Wait");
myCommand.Parameters.Add(testParam);
myCommand.Parameters.Add(testParam2);
myCommand.Parameters.Add(testParam3);
pipeline.Commands.Add(myCommand);
var results = pipeline.Invoke();
但是,当我尝试使用以下命令参数启用RabbitMQ管理插件时,它不会影响任何事情。实际发生的情况是,在执行此代码之后,新的命令提示符会以很小的比例打开和关闭
这是我试过的代码
CommandParameter testParam = new CommandParameter("FilePath", @"""C:\Program Files\RabbitMQ Server\rabbitmq_server-3.8.3\sbin\rabbitmq-plugins.bat""");
CommandParameter testParam2 = new CommandParameter("ArgumentList", new string[] { "'enable rabbitmq_management'" });
CommandParameter testParam3 = new CommandParameter("Wait");
试试这个:
var startInfo =
new ProcessStartInfo
{
FileName = @"C:\Windows\System32\cmd.exe",
Arguments = "/c rabbitmq-plugins enable rabbitmq_management",
WorkingDirectory = @"C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.11\sbin",
WindowStyle = ProcessWindowStyle.Maximized
};
Process.Start(startInfo)?.WaitForExit();
Process.Start("net", "stop RabbitMQ")?.WaitForExit();
Process.Start("net", "start RabbitMQ")?.WaitForExit();
我是通过遵循这个代码来工作的
private static string RunScript(string scriptText)
{
// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
// open it
runspace.Open();
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
// add an extra command to transform the script
// output objects into nicely formatted strings
// remove this line to get the actual objects
// that the script returns. For example, the script
// "Get-Process" returns a collection
// of System.Diagnostics.Process instances.
pipeline.Commands.Add("Out-String");
// execute the script
pipeline.Invoke();
// close the runspace
runspace.Close();
}
还是没有变化。。它仍然会产生相同的结果,即打开一个新的命令提示符,并在它打开后立即将其关闭以管理员身份运行visual studio。