public double ExecuteScript(string script) { File.WriteAllText(_path, script); var start = new ProcessStartInfo { FileName = @"python", CreateNoWindow = true, Arguments = string.Format("{0}", _path), UseShellExecute = false, RedirectStandardOutput = true, }; using (Process process = Process.Start(start)) { using (StreamReader reader = process.StandardOutput) { ReadToEndDelegate asyncCall = reader.ReadToEnd; IAsyncResult asyncResult = asyncCall.BeginInvoke(null, null); asyncResult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(_timeout)); if (asyncResult.IsCompleted) { var processResult = asyncCall.EndInvoke(asyncResult); return(processResult.GetDouble(-1.0d)); } return(-1.0d); } } }
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; } }
public RemoteExecutableResults Run(string arguments) { using (Process process = new Process()) { process.StartInfo.FileName = _executablePath; process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = this.WorkingDirectory; 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 TimeoutException( 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 TimeoutException( 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); RemoteExecutableResults result = new RemoteExecutableResults(); result.ExitCode = process.ExitCode; result.Output = output; return(result); } }
public RemoteExecutableResults Run(string arguments) { using (Process process = new Process()) { process.StartInfo.FileName = _executablePath; process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = this.WorkingDirectory; 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 TimeoutException( 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 TimeoutException( 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); RemoteExecutableResults result = new RemoteExecutableResults(); result.ExitCode = process.ExitCode; result.Output = output; return result; } }