BEurtle.BEurtlePlugin.callBEcmd C# (CSharp) 메소드

callBEcmd() 공개 메소드

public callBEcmd ( string BErepopath, string arguments, string inputs = null ) : string[]
BErepopath string
arguments string
inputs string
리턴 string[]
        public string[] callBEcmd(string BErepopath, string[] arguments, string[] inputs = null)
        {
            string[] outputs = new string[arguments.Length];
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                for (var i = 0; i < arguments.Length; i++)
                {
                    string arguments_ = arguments[i];
                    if (BErepopath.StartsWith("http://"))
                        arguments_ = "--repo " + BErepopath + " " + arguments_;
                    var process = new Process
                    {
                        StartInfo = new ProcessStartInfo
                        {
                            CreateNoWindow = true,
                            FileName = parameters.BEPath,
                            Arguments = arguments_,
                            RedirectStandardInput = true,
                            RedirectStandardOutput = true,
                            RedirectStandardError = true,
                            StandardErrorEncoding=Encoding.UTF8,
                            StandardOutputEncoding=Encoding.UTF8,
                            UseShellExecute = false,
                            WorkingDirectory = BErepopath.StartsWith("http://") ? rootpath : BErepopath
                        }
                    };
                    process.StartInfo.EnvironmentVariables.Add("BE_ENCODING", "UTF-8");
                    process.StartInfo.EnvironmentVariables.Add("BE_INPUT_ENCODING", "UTF-8");
                    process.StartInfo.EnvironmentVariables.Add("BE_OUTPUT_ENCODING", "UTF-8");
                    try
                    {
                        string output = "", error = "";
                        process.OutputDataReceived += new DataReceivedEventHandler((sender, e) => output += e.Data);
                        process.ErrorDataReceived += new DataReceivedEventHandler((sender, e) => error += e.Data);
                        if (!process.Start()) throw new Exception(parameters.BEPath + " not found");
                        process.BeginOutputReadLine();
                        process.BeginErrorReadLine();
                        if (inputs != null && inputs[i].Length > 0)
                            process.StandardInput.Write(inputs[i]);
                        process.StandardInput.Close();
                        process.WaitForExit();
                        outputs[i] = output + error;
                    }
                    catch (Exception e)
                    {
                        outputs[i] = e.Message;
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
            return outputs;
        }