Example #1
0
        public override void Start(AssetBuildContext context)
        {
            Context = context;
            try
            {
                Output.Clear();
                ErrorOutput.Clear();

                m_RunningProcess           = new Process();
                m_RunningProcess.StartInfo = StartInfo;

                // Enable async events
                m_RunningProcess.EnableRaisingEvents = true;
                m_RunningProcess.Exited             += new EventHandler(ExitHandler);
                m_RunningProcess.OutputDataReceived += new DataReceivedEventHandler(OnOutput);
                m_RunningProcess.ErrorDataReceived  += new DataReceivedEventHandler(OnErrorOutput);

                m_RunningProcess.Start();
                m_RunningProcess.BeginOutputReadLine();
                m_RunningProcess.BeginErrorReadLine();
            }
            catch (Exception exp)
            {
                ToolDebug.Error("Failed to run {0}, {1}", StartInfo.FileName, exp.Message);
                m_RunningProcess = null;
                // Log error.
            }
        }
Example #2
0
        /// <summary>
        /// Start the process synchronously
        /// </summary>
        public bool DoWait(bool hidden = false)
        {
            StandardOutput.Clear();
            ErrorOutput.Clear();

            if (hidden)
            {
                StartInfo.CreateNoWindow = true;
                StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
            }

            if (!string.IsNullOrEmpty(Arguments))
            {
                StartInfo.Arguments = Arguments;
            }

            if (_nbExecution > 0)
            {
                Kill();
            }

            _nbExecution++;

            if (_process == null)
            {
                _process = new Process {
                    StartInfo = StartInfo
                };
                _process.OutputDataReceived += (sender, args) => StandardOutput.AppendLine(args.Data);
                _process.ErrorDataReceived  += (sender, args) => ErrorOutput.AppendLine(args.Data);
            }

            _process.Start();
            _process.WaitForExit();

            ExitCode = _process.ExitCode;

            return(ExitCode == 0);
        }