public ExecutableResults Run(string arguments) { using (Process process = new Process()) { process.StartInfo.FileName = _executablePath; if (!System.IO.File.Exists(_executablePath)) { throw new TestFailedException("Unable to find file to execute:" + _executablePath); } process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = this.WorkingDirectory; AstoriaTestLog.TraceLine("Commandline tool arguments:" + arguments); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.Start(); ReadToEndDelegate readToEnd = new ReadToEndDelegate(process.StandardOutput.ReadToEnd); IAsyncResult readToEndResult = readToEnd.BeginInvoke(null, null); try { process.WaitForExit(_millisecondsToWait); } catch (System.ComponentModel.Win32Exception win32Exception) { throw new TestFailedException( String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}", _executablePath, _millisecondsToWait / 1000, System.Environment.NewLine, win32Exception.Message)); } catch (System.SystemException systemException) { throw new TestFailedException( String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}", _executablePath, _millisecondsToWait / 1000, System.Environment.NewLine, systemException.Message)); } string output = readToEnd.EndInvoke(readToEndResult); ExecutableResults result = new ExecutableResults(process.ExitCode, output); return(result); } }
public ExecutableResults Run(string arguments) { using (Process process = new Process()) { process.StartInfo.FileName = _executablePath; if (!System.IO.File.Exists(_executablePath)) throw new TestFailedException("Unable to find file to execute:" + _executablePath); process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = this.WorkingDirectory; AstoriaTestLog.TraceLine("Commandline tool arguments:"+arguments); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.Start(); ReadToEndDelegate readToEnd = new ReadToEndDelegate(process.StandardOutput.ReadToEnd); IAsyncResult readToEndResult = readToEnd.BeginInvoke(null, null); try { process.WaitForExit(_millisecondsToWait); } catch (System.ComponentModel.Win32Exception win32Exception) { throw new TestFailedException( String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}", _executablePath, _millisecondsToWait / 1000, System.Environment.NewLine, win32Exception.Message)); } catch (System.SystemException systemException) { throw new TestFailedException( String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}", _executablePath, _millisecondsToWait / 1000, System.Environment.NewLine, systemException.Message)); } string output = readToEnd.EndInvoke(readToEndResult); ExecutableResults result = new ExecutableResults(process.ExitCode, output); return result; } }