Ejemplo n.º 1
0
        internal int Execute(string prefix)
        {
            Defaults.Logger.Write(prefix, Path + _argumentBuilder.Build());
            int exitCode = 0;

            using (IProcessWrapper process = CreateProcess())
            {
                try
                {
                    process.Start();
                    process.BeginOutputAndErrorReadLine();
                    if (!process.WaitForExit(_timeoutInMiliSeconds))
                    {
                        HandleTimeout(process);
                    }

//					if( _noErrorMessageWhenExitCodeZero && process.ExitCode == 0)
//					{
//						_output.Append( _error );
//						_error.Clear();
//					}

                    _messageProcessor.Display(prefix, _output.ToString(), _error.ToString(), process.ExitCode);
                    exitCode = process.ExitCode;

                    //if we are supposed to fail on errors
                    //and there was an error
                    //and the calling code has decided not to deal with the error code (by setting SucceedOnNonZeroErrorCodes
                    //then set the environment exit code
                    if (OnError == OnError.Fail && exitCode != 0 && _succeedOnNonZeroErrorCodes == false)
                    {
                        BuildFile.SetErrorState();
                        throw new ApplicationException("Executable returned an error code of " + exitCode);
                    }
                }
                catch (Exception e)
                {
                    if (OnError == OnError.Fail)
                    {
                        throw;
                    }
                    Debug.Write(prefix, "An error occurred running a process but FailOnError was set to false. Error: " + e);
                }
            }

            this.ExitCode = exitCode;
            return(exitCode);
        }