Exemplo n.º 1
0
        /// <summary>
        /// Starts an external process.
        /// </summary>
        /// <param name="scriptPart">Script part which represents the external process to start.</param>
        /// <returns>Cli Return Code</returns>
        private int StartExternalProcess(ScriptPart scriptPart)
        {
            int result = 0;

            try
            {
                Process proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName               = scriptPart.Program,
                        Arguments              = scriptPart.Arguments,
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        CreateNoWindow         = true
                    }
                };

                proc.Start();
                _logger.NewLine();
                while (!proc.StandardOutput.EndOfStream)
                {
                    string line = proc.StandardOutput.ReadLine();
                    _logger.PrintExternalScriptOutput(line);
                }
                _logger.NewLine();
            }
            catch (Exception e)
            {
                _logger.ExternalScriptException(e);

                result = 1;
            }

            return(result);
        }