c# - 使用 C# 启用 RabbitMQ 管理插件
问题描述
我一直在尝试使用 C# 代码启用 RabbitMQ 管理插件。
通过使用以下代码,我成功地使用 c# 安装了 RabbitMQ 服务器。
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();
但是,当我尝试使用以下 CommandParameters 启用 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");
解决方案
我通过遵循此代码得到了这个工作。
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();
}
推荐阅读
- html - 防止字符串在表格标签内不中断
- python - 熊猫按列规范化行
- python - 将字符串数组从 python 传递到 C 并在 for 循环中使用(包括代码)
- reactjs - Google 登录,在使用 ReactJS 的扩展中 - 错误无法读取未定义的属性“加载”
- spring - Jpa最大值请求
- python - 没有名为 pyarrow 的模块
- django - {% include %} 不会在其他 html 页面中传递“for loop”数据 - Django
- c++ - 使用 cmake 安装动态库
- kivy - ScatterLayout - do_translation 不起作用
- python - Discord.py - 机器人启动时加载公会前缀 (MySQL)