private static 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));
     process.Kill();
     if (! process.WaitForExit(WAIT_FOR_KILLED_PROCESS_TIMEOUT))
         throw new Exception(
             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));
     Log.Warning(string.Format("The timed out process has been killed: {0}", process.Id));
 }
Exemple #2
0
        public virtual ProcessResult Execute(ProcessInfo processInfo)
        {
            using (var process = Start(processInfo))
            {
                using (
                    ProcessReader standardOutput = new ProcessReader(process.StandardOutput),
                    standardError = new ProcessReader(process.StandardError))
                {
                    WriteToStandardInput(process, processInfo);

                    var 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));
                }
            }
        }
        public virtual ProcessResult Execute(ProcessInfo processInfo)
        {
            using (var process = Start(processInfo))
            {
                using (
                    ProcessReader standardOutput = new ProcessReader(process.StandardOutput),
                                  standardError = new ProcessReader(process.StandardError))
                {
                    WriteToStandardInput(process, processInfo);

                    var 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);
                }
            }
        }