Beispiel #1
0
        /// <summary>
        /// 构造一个命令行配置器对话窗
        /// </summary>
        /// <param name="command">传入的命令</param>
        public CommandSetter(BatCommand command)
        {
            InitializeComponent();
            _command                       = command;
            this.Text                     += command.CommandName;
            this.lbPreview.Text            = this.lbCommandName.Text = command.CommandName;
            this.lbCommandDisctiption.Text = command.CommandDiscription;

            if (!command.IsLoaded)
            {
                command.Load();
            }
            this.tbCommandUseage.Text = command.Usege;
        }
Beispiel #2
0
        /// <summary>
        /// 获取内部命令
        /// </summary>
        public static List <BatCommand> GetInternalCommand()
        {
            // 实例一个Process类,启动一个独立进程
            Process p = new Process
            {
                StartInfo =
                {
                    FileName               = "cmd.exe", // 设定程序名
                    Arguments              = "/A /c help",
                    UseShellExecute        = false,     // 关闭Shell的使用
                    RedirectStandardInput  = false,     // 重定向标准输入
                    RedirectStandardOutput = true,      // 重定向标准输出
                    RedirectStandardError  = false,     //重定向错误输出
                    CreateNoWindow         = true       // 设置不显示窗口
                }
            };

            p.Start();
            // 从输出流获取命令执行结果
            string result = p.StandardOutput.ReadToEnd();

            p.Close();


            string[] tmp = result.Split(new string[] { "\r\n" }, StringSplitOptions.None);

            List <BatCommand> returnValue = new List <BatCommand>();
            int index = 0;

            //剔除第一行和最后3行
            for (int i = 1; i < tmp.Length - 3; i++)
            {
                string[] str = tmp[i].Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (string.IsNullOrEmpty(str[0]))
                {
                    continue;
                }


                switch (str.Length)
                {
                case 1:
                    returnValue[index - 1].CommandDiscription += str[0];
                    break;

                case 2:
                    BatCommand bc = new BatCommand(str[0])
                    {
                        IsInternal         = true,
                        Usege              = null,
                        IsLoaded           = false,
                        CommandDiscription = str[1]
                    };
                    returnValue.Add(bc);
                    index++;
                    break;

                default:
                    StringBuilder sb = new StringBuilder();
                    for (int j = 1; j < str.Length; j++)
                    {
                        sb.Append(str[j]);
                    }
                    BatCommand bc2 = new BatCommand(str[0])
                    {
                        IsInternal         = true,
                        Usege              = null,
                        IsLoaded           = false,
                        CommandDiscription = sb.ToString()
                    };
                    returnValue.Add(bc2);
                    index++;
                    break;
                }
            }

            return(returnValue);
        }