コード例 #1
0
ファイル: ProcessExecutor.cs プロジェクト: vardars/ci-factory
 private void Kill(Process process, ProcessInfo processInfo, ProcessReader standardOutput, ProcessReader standardError)
 {
     Log.Warning(string.Format("Process timed out: {0} {1}.  Process id: {2}.  This process will now be killed.", processInfo.FileName, processInfo.Arguments, process.Id));
     Log.Debug(string.Format("Process stdout: {0}", standardOutput.Output));
     Log.Debug(string.Format("Process stderr: {0}", standardError.Output));
     try
     {
         process.Kill();
         if (! process.WaitForExit(WAIT_FOR_KILLED_PROCESS_TIMEOUT))
             throw new CruiseControlException(string.Format(@"The killed process {0} did not terminate within the allotted timeout period {1}.  The process or one of its child processes may not have died.  This may create problems when trying to re-execute the process.  It may be necessary to reboot the server to recover.", process.Id, WAIT_FOR_KILLED_PROCESS_TIMEOUT, process));
     }
     catch (InvalidOperationException)
     {
         Log.Warning(string.Format("Process has already exited before getting killed: {0}", process.Id));
     }
     Log.Warning(string.Format("The timed out process has been killed: {0}", process.Id));
 }
コード例 #2
0
        public virtual ProcessResult Execute(ProcessInfo processInfo)
        {
            Log.Debug(string.Format("Executing process {0} {1} in {2}", processInfo.FileName, processInfo.Arguments, processInfo.WorkingDirectory));
            using (Process process = Start(processInfo))
            {
                using (ProcessReader standardOutput = new ProcessReader(process.StandardOutput), standardError = new ProcessReader(process.StandardError))
                {
                    WriteToStandardInput(process, processInfo);

                    bool hasExited = process.WaitForExit(processInfo.TimeOut);
                    if (hasExited)
                    {
                        standardOutput.WaitForExit();
                        standardError.WaitForExit();
                    }
                    else
                    {
                        Kill(process, processInfo, standardOutput, standardError);
                    }
                    return(new ProcessResult(standardOutput.Output, standardError.Output, process.ExitCode, !hasExited));
                }
            }
        }
コード例 #3
0
ファイル: ProcessExecutor.cs プロジェクト: vardars/ci-factory
        public virtual ProcessResult Execute(ProcessInfo processInfo)
        {
            Log.Debug(string.Format("Executing process {0} {1} in {2}", processInfo.FileName, processInfo.Arguments, processInfo.WorkingDirectory));
            using (Process process = Start(processInfo))
            {
                using (ProcessReader standardOutput = new ProcessReader(process.StandardOutput), standardError = new ProcessReader(process.StandardError))
                {
                    WriteToStandardInput(process, processInfo);

                    bool hasExited = process.WaitForExit(processInfo.TimeOut);
                    if (hasExited)
                    {
                        standardOutput.WaitForExit();
                        standardError.WaitForExit();
                    }
                    else
                    {
                        Kill(process, processInfo, standardOutput, standardError);
                    }
                    return new ProcessResult(standardOutput.Output, standardError.Output, process.ExitCode, ! hasExited);
                }
            }
        }
コード例 #4
0
 private void Kill(Process process, ProcessInfo processInfo, ProcessReader standardOutput, ProcessReader standardError)
 {
     Log.Warning(string.Format("Process timed out: {0} {1}.  Process id: {2}.  This process will now be killed.", processInfo.FileName, processInfo.Arguments, process.Id));
     Log.Debug(string.Format("Process stdout: {0}", standardOutput.Output));
     Log.Debug(string.Format("Process stderr: {0}", standardError.Output));
     try
     {
         process.Kill();
         if (!process.WaitForExit(WAIT_FOR_KILLED_PROCESS_TIMEOUT))
         {
             throw new CruiseControlException(string.Format(@"The killed process {0} did not terminate within the allotted timeout period {1}.  The process or one of its child processes may not have died.  This may create problems when trying to re-execute the process.  It may be necessary to reboot the server to recover.", process.Id, WAIT_FOR_KILLED_PROCESS_TIMEOUT, process));
         }
     }
     catch (InvalidOperationException)
     {
         Log.Warning(string.Format("Process has already exited before getting killed: {0}", process.Id));
     }
     Log.Warning(string.Format("The timed out process has been killed: {0}", process.Id));
 }