星号执行CLI命令C# [英] execute asterisk cli command C#

查看:231
本文介绍了星号执行CLI命令C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行使用C#星号CLI命令的帮助。我能打开终端窗口,启动星号(见下面的代码),但不知道如何例如实行一口秀同行,在CLI命令。 ?是否有任何可能的方式来做到这一点。



 使用系统;使用System.Diagnostics程序
;

命名空间runGnomeTerminal
{
类MainClass
{
公共静态无效ExecuteCommand(字符串命令)
{
过程PROC =新的System.Diagnostics.Process();
proc.StartInfo.FileName =/斌/ bash的;
proc.StartInfo.Arguments =-c \+指令+\;
proc.StartInfo.UseShellExecute = FALSE;
proc.StartInfo.RedirectStandardOutput = TRUE;
proc.Start();

{时
Console.WriteLine(proc.StandardOutput.ReadLine())(proc.StandardOutput.EndOfStream!);
}
}

公共静态无效的主要(字串[] args)
{
ExecuteCommand(GNOME终端的bash -x -icCD $ HOME; sudo的星号-vvvvr;庆典');

}
}
}


解决方案

所有你triing做的是矫枉过正。你只需要问的星号命令,在bash或终端没有必要。

 过程PROC =新的System.Diagnostics.Process() ; 
proc.StartInfo.FileName =/ usr / sbin目录/星号;
proc.StartInfo.Arguments =-rx \+指令+\;
proc.StartInfo.UseShellExecute = FALSE;
proc.StartInfo.RedirectStandardOutput = TRUE;
proc.Start();



但请注意,该命令开始新的星号的过程,所以不是最佳的。最好的办法是用星号AMI接口(这仅仅是tcp连接,那么多资源少使用)和AMI发出动作指令。
有已经开发AMI接口,包括C#一个数字。


I need a help with executing asterisk cli commands using C#. I'm able to open terminal window and start asterisk (see the code below), but dont know how to for example execute "sip show peers" command in CLI. Is there any possible way to do it?

using System;
using System.Diagnostics;

namespace runGnomeTerminal
{
    class MainClass
    {
        public static void ExecuteCommand(string command)
        {
            Process proc = new System.Diagnostics.Process ();
            proc.StartInfo.FileName = "/bin/bash";
            proc.StartInfo.Arguments = "-c \" " + command + " \"";
            proc.StartInfo.UseShellExecute = false; 
            proc.StartInfo.RedirectStandardOutput = true;
            proc.Start ();

            while (!proc.StandardOutput.EndOfStream) {
                Console.WriteLine (proc.StandardOutput.ReadLine ());
            }
        }

        public static void Main (string[] args)
        {
            ExecuteCommand("gnome-terminal -x bash -ic 'cd $HOME; sudo asterisk -vvvvr; bash'");

        }
    }
}

解决方案

All you triing to do is overkill. You just need ask asterisk for command, no need in bash or terminal.

Process proc = new System.Diagnostics.Process ();
proc.StartInfo.FileName = "/usr/sbin/asterisk";
proc.StartInfo.Arguments = "-rx \" " + command + " \"";
proc.StartInfo.UseShellExecute = false; 
proc.StartInfo.RedirectStandardOutput = true;
proc.Start ();

But please note, that command start NEW asterisk process, so not optimal. Best way is use asterisk AMI interface(which is just tcp connection, so much less resources use) and issue AMI action COMMAND. There are number of already developed AMI interfaces, including C# one.

这篇关于星号执行CLI命令C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆