我试图使用与管道运行bash命令管道COMAND单过程开始运行bash从单一的Linux
这里的代码片断我试图
单指令的作品,但是管的命令无法运行,有什么我在这里想念吗?
ProcessStartInfo oInfo = new ProcessStartInfo(command, args);
oInfo.UseShellExecute = false;
oInfo.CreateNoWindow = true;
oInfo.RedirectStandardOutput = true;
oInfo.RedirectStandardError = true;
StreamReader srOutput = null;
StreamReader srError = null;
Process proc = System.Diagnostics.Process.Start(oInfo);
proc.WaitForExit();
我试着运行“ps -aux”,它运行良好。但是ps -aux | grep gnome命令失败。
我试过这些场景 场景1: command = ps argument = -aux | grep的侏儒
场景2: 命令= PS 参数= “-c '-aux | grep的侏儒'”
场景3:
命令= PS 参数= “-c \” - aux | grep的侏儒\”“
所有这些失败,
错误:垃圾选项
用法: PS [选项]
尝试 'PS --help' 或“PS --help ' 获取更多帮助文本。
另外在侧面的问题,我试图做到这一点的原因是找出一个特定的守护进程已经运行。有没有一个标准的方式来获得这个信息。例如在Windows中我们可以使用ServiceController.GetServices()查询正在运行的服务。
直接在mono/Linux上有类似的东西吗?