private void userControl_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (SystemContext.Instance.TileMode == Enums.TileMode.Normal) { ProcessExecutor.Execute(this.AppMeta); } }
public void ExecuteWritesToStdIn() { var fileSystemMock = InitialiseFileSystemMockForExecute(); var info = new ProcessInfo("sleeper", "1") { StandardInputContent = "SomeData" }; var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object }; var projectName = "aProject"; var waitHandle = new ManualResetEvent(false); ProcessResult result = null; var thread = new Thread( () => { try { result = executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt"); } finally { waitHandle.Set(); } }); thread.Start(); waitHandle.WaitOne(TimeSpan.FromSeconds(30)); Assert.IsTrue(result.Succeeded); }
public void ExecuteChangesPriority() { var fileSystemMock = InitialiseFileSystemMockForExecute(); var info = new ProcessInfo("sleeper", "1", null, ProcessPriorityClass.BelowNormal); var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object }; var projectName = "aProject"; var waitHandle = new ManualResetEvent(false); ProcessResult result = null; var thread = new Thread( () => { try { result = executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt"); } finally { waitHandle.Set(); } }); thread.Start(); waitHandle.WaitOne(TimeSpan.FromSeconds(30)); Assert.IsTrue(result.Succeeded); }
public void DotnetInfoTest() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } using var executor = new ProcessExecutor("dotnet", "--info"); var list = new List <string>(); executor.OnOutputDataReceived += (sender, str) => { list.Add(str); }; var exitCode = -1; executor.OnExited += (sender, code) => { exitCode = code; }; executor.Execute(); Assert.NotEmpty(list); Assert.Equal(0, exitCode); }
protected virtual string Execute(ProcessInfo p) { Log.Debug("Perforce plugin - running:" + p.ToString()); ProcessResult result = processExecutor.Execute(p); return(result.StandardOutput.Trim() + Environment.NewLine + result.StandardError.Trim()); }
private ProcessResult TryToRun(IIntegrationResult result) { ProcessInfo processInfo = new ProcessInfo(Executable, GetArguments(result), result.WorkingDirectory, Priority); processInfo.TimeOut = BuildTimeoutSeconds * 1000; IDictionary properties = result.IntegrationProperties; // pass user defined the environment variables foreach (EnvironmentVariable item in EnvironmentVariables) { processInfo.EnvironmentVariables[item.name] = item.value; } // Pass the integration environment variables to devenv. foreach (string key in properties.Keys) { processInfo.EnvironmentVariables[key] = StringUtil.IntegrationPropertyToString(properties[key]); } Log.Info(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Starting build: {0} {1}", processInfo.FileName, processInfo.PublicArguments)); try { return(executor.Execute(processInfo)); } catch (IOException ex) { string message = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unable to launch the devenv process. Please verify that you can invoke this command from the command line: {0} {1}", processInfo.FileName, processInfo.PublicArguments); throw new BuilderException(this, message, ex); } }
public void ExecuteTimesOut() { var fileSystemMock = InitialiseFileSystemMockForExecute(); var info = new ProcessInfo("sleeper") { TimeOut = TimeSpan.FromSeconds(1) }; var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object }; var projectName = "aProject"; var waitHandle = new ManualResetEvent(false); ProcessResult result = null; var thread = new Thread( () => { try { result = executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt"); } finally { waitHandle.Set(); } }); thread.Start(); waitHandle.WaitOne(TimeSpan.FromSeconds(30)); Assert.IsTrue(result.TimedOut); }
public void ExecutePassesOnOutput() { var fileSystemMock = InitialiseFileSystemMockForExecute(); var info = new ProcessInfo("sleeper", "1"); var output = new List <ProcessOutputEventArgs>(); var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object }; executor.ProcessOutput += (o, e) => output.Add(e); var projectName = "aProject"; var waitHandle = new ManualResetEvent(false); ProcessResult result = null; var thread = new Thread( () => { try { result = executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt"); } finally { waitHandle.Set(); } }); thread.Start(); waitHandle.WaitOne(TimeSpan.FromSeconds(30)); CollectionAssert.IsNotEmpty(output); Assert.IsTrue(result.Succeeded); }
public void Create(AppInfo appInfo, string executablePath) { var arguments = executablePath.EndsWith(".exe") ? $"create {appInfo} DisplayName= \"{appInfo}\" binpath= \"{executablePath} {WindowsServiceOption} {SetWorkingDirectoryOption}\"" : $"create {appInfo} DisplayName= \"{appInfo}\" binpath= \"{DotnetExecutable} {executablePath} {WindowsServiceOption} {SetWorkingDirectoryOption}\""; ProcessExecutor.Execute(ScExecutable, nameof(Create), arguments); }
private static void Main(string[] args) { var clientProcess = new ClientProcess(); if (clientProcess.Deserialize()) { Console.WriteLine("I'm called"); // receive arguments from caller process var deserializer = clientProcess.Deserializer; var person1 = deserializer.GetArgument <Person>("person1"); var person2 = deserializer.GetArgument <Person>(1); var myDog = deserializer.GetArgument <Dog>("myDog"); var myString = deserializer.GetArgument <string>(3); var myCode = deserializer.GetArgument <int>(4); Console.WriteLine(person1); Console.WriteLine(person2); Console.WriteLine(myDog); Console.WriteLine(myString); Console.WriteLine(myCode); // communicate with caller process clientProcess.Transmitter.PrepareAsync().Wait(); var message = clientProcess.Transmitter.Receive <string>(); Console.WriteLine(message); } else { Console.WriteLine("I'm calling"); ProcessExecutor executor = new ProcessExecutor("Example.exe");// execute itself // pass arguments while calling executor.Add("person1", new Person() { Name = "tran xuan son", Age = 23 }); executor.Add(new Person() { Name = "tran xuan soan", Age = 24 }); executor.Add("myDog", new Dog() { CoatColor = "black", Type = "i don't know" }); executor.Add("some string"); executor.Add(3393); executor.Execute(); // communicate with process that is called executor.Transmitter.PrepareAsync().Wait(); executor.Transmitter.Send("ok, i am fine"); } Console.Read(); }
private void DeleteClientSpec(P4 p4) { ProcessResult result = executor.Execute(infoCreator.CreateProcessInfo(p4, "client -d " + p4.Client)); if (result.ExitCode != ProcessResult.SUCCESSFUL_EXIT_CODE) { throw new CruiseControlException(string.Format("Failed to Initialize client (exit code was {0}).\r\nStandard output was: {1}\r\nStandard error was {2}", result.ExitCode, result.StandardOutput, result.StandardError)); } }
public static void DotNetInfoTest() { using var executor = new ProcessExecutor("dotnet", "--info"); executor.OnOutputDataReceived += (sender, str) => { Console.WriteLine(str); }; executor.Execute(); }
/// <summary> /// Attempts to execute. /// </summary> /// <param name="info">The info.</param> /// <param name="projectName">Name of the project.</param> /// <returns></returns> /// <remarks></remarks> protected ProcessResult AttemptToExecute(ProcessInfo info, string projectName) { try { return(_executor.Execute(info)); } catch (Exception e) { throw new BuilderException(this, string.Format(System.Globalization.CultureInfo.CurrentCulture, "FBCMD unable to execute: {0}\n{1}", info, e), e); } }
public void Run(IIntegrationResult result) { ProcessResult processResult = executor.Execute(NewProcessInfo(result)); string buildOutputFile = MsBuildOutputFile(result); if (File.Exists(buildOutputFile)) { result.AddTaskResult(new FileTaskResult(buildOutputFile)); } result.AddTaskResult(new ProcessTaskResult(processResult)); }
protected ProcessResult AttemptToExecute(ProcessInfo info) { try { return(executor.Execute(info)); } catch (Exception e) { throw new BuilderException(this, string.Format("Unable to execute: {0}\n{1}", info, e), e); } }
protected ProcessResult AttemptExecute(ProcessInfo info, string projectName) { try { return(executor.Execute(info, projectName)); } catch (Exception e) { throw new BuilderException(this, string.Format("Unable to execute: {0}\n{1}", BuildCommand, e), e); } }
/// <summary> /// Runs the Subversion process. /// </summary> /// <param name="arguments">The command-line arguments.</param> /// <returns>The results of executing the process including output.</returns> protected virtual ProcessResult RunSvnProcess(ProcessArgumentBuilder arguments) { // prepare process ProcessInfo info = new ProcessInfo(Executable, arguments.ToString()); // execute process ProcessExecutor executor = new ProcessExecutor(); ProcessResult result = executor.Execute(info); // return results return(result); }
public static ProcessResult RunSvnProcess(SvnOptions svnLoginOptions, ProcessArgumentBuilder argBuilder) { argBuilder.AddArgument("--non-interactive"); argBuilder.AddArgument("--no-auth-cache"); ProcessInfo info = new ProcessInfo("svn.exe", argBuilder.ToString()); ProcessExecutor executor = new ProcessExecutor(); ProcessResult result = executor.Execute(info); return(result); }
private void SetupExecutorMock(ProcessExecutor executor, string fileName, string args, string workingDir, int timeout) { Expect.Call(executor.Execute(null)) .IgnoreArguments() .Do(new Function <ProcessInfo, ProcessResult>(info => { Assert.AreEqual(fileName, info.FileName); Assert.AreEqual(args, info.Arguments); Assert.AreEqual(workingDir, info.WorkingDirectory); Assert.AreEqual(timeout, info.TimeOut); return(new ProcessResult(string.Empty, string.Empty, 0, false)); })); }
public void ProcessShallPassCustomEnvironment() { var cmd = "Resources/Scripts/envtest." + (FdOs.IsWindows() ? "bat" : "sh"); var file = Path.Combine(Directory.GetCurrentDirectory(), (TemplateString)cmd); var executor = new ProcessExecutor <StringListResponseParser, IList <string> >(file, string.Empty); executor.Env["FD_CUSTOM_ENV"] = "My test environment variable"; var result = executor.Execute(); Assert.AreEqual("My test environment variable", result.Data[FdOs.IsWindows() ? 1 : 0]); }
/// <summary> /// Try Execute a command /// </summary> public GitResult TryExecute(string command) { try { var result = ProcessExecutor.Execute(Location, command, Encoding.UTF8); return(new GitResult( result.Out, result.Error, result.ExitCode)); } catch (IOException) { return(GitResult.GitNotFound); } }
/// <summary> /// Initializes the specified p4. /// </summary> /// <param name="p4">The p4.</param> /// <param name="project">The project.</param> /// <param name="workingDirectory">The working directory.</param> /// <remarks></remarks> public void Initialize(P4 p4, string project, string workingDirectory) { CheckWorkingDirectoryIsValid(workingDirectory); CheckViewIsValid(p4.ViewForSpecifications); CreateClientNameIfOneNotSet(p4, project); ProcessInfo processInfo = processInfoCreator.CreateProcessInfo(p4, "client -i"); processInfo.StandardInputContent = CreateClientSpecification(p4, workingDirectory); ProcessResult result = executor.Execute(processInfo); if (result.ExitCode != ProcessResult.SUCCESSFUL_EXIT_CODE) { throw new CruiseControlException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Failed to Initialize client (exit code was {0}).\r\nStandard output was: {1}\r\nStandard error was {2}", result.ExitCode, result.StandardOutput, result.StandardError)); } }
private void StartLogman() { ProcessExecutor processExecutor = new ProcessExecutor("logman", "start PatchOrchestrationServiceTraces"); int exitCode = processExecutor.Execute(); if (exitCode != 0) { _eventSource.InfoMessage( "Not able to start logman session - 'PatchOrchestrationServiceTraces'. Exit code: {0}", exitCode); } else { _eventSource.InfoMessage("Logman session 'PatchOrchestrationServiceTraces' started."); } }
public virtual void Run(IIntegrationResult result) { string outputFile = result.BaseFromArtifactsDirectory(OutputFile); ProcessResult nunitResult = processExecutor.Execute(NewProcessInfo(outputFile, result), result.ProjectName); result.AddTaskResult(new ProcessTaskResult(nunitResult)); if (File.Exists(outputFile)) { result.AddTaskResult(new FileTaskResult(outputFile)); } else { Log.Warning(string.Format("NUnit test output file {0} was not created", outputFile)); } }
private ProcessResult AttemptToExecute(string workingDirectory) { ProcessInfo processInfo = new ProcessInfo(Executable, Arguments, workingDirectory); processInfo.TimeOut = BuildTimeoutSeconds * 1000; Log.Info(string.Format("Starting build: {0} {1}", processInfo.FileName, processInfo.Arguments)); try { return(executor.Execute(processInfo)); } catch (Exception ex) { string message = string.Format("Unable to launch the devenv process. Please verify that you can invoke this command from the command line: {0} {1}", processInfo.FileName, processInfo.Arguments); throw new BuilderException(this, message, ex); } }
/// <summary> /// Executes the specified process. /// </summary> /// <param name="process">The process.</param> /// <param name="description">The description.</param> /// <returns></returns> /// <remarks></remarks> protected virtual string Execute(ProcessInfo process, string description) { Log.Info(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Perforce {0}: {1} {2}", description, process.FileName, process.PublicArguments)); ProcessResult result = processExecutor.Execute(process); string errorSummary = ParseErrors(result.StandardOutput, result.StandardError); if (errorSummary != null) { string errorMessage = string.Format( CultureInfo.CurrentCulture, "Perforce {0} failed: {1} {2}\r\nError output from process was: \r\n{3}", description, process.FileName, process.PublicArguments, errorSummary); Log.Error(errorMessage); throw new CruiseControlException(errorMessage); } return(result.StandardOutput.Trim() + Environment.NewLine + result.StandardError.Trim()); }
//public virtual void Run(IIntegrationResult result) //{ // // Initialise the task // this.WasSuccessful = false; // if ((this.currentStatus == null) || // (this.currentStatus.Status != ItemBuildStatus.Running)) // { // InitialiseStatus(ItemBuildStatus.Pending); // currentStatus.Status = ItemBuildStatus.Running; // } // // Perform the actual run // currentStatus.TimeOfEstimatedCompletion = CalculateEstimatedTime(); // currentStatus.TimeStarted = DateTime.Now; // try // { // this.WasSuccessful = Execute(result); // } // catch (Exception error) // { // // Store the error message // currentStatus.Error = error.Message; // result.Status = IntegrationStatus.Exception; // throw; // } // finally // { // // Clean up // currentStatus.Status = (this.WasSuccessful) ? ItemBuildStatus.CompletedSuccess : ItemBuildStatus.CompletedFailed; // currentStatus.TimeCompleted = DateTime.Now; // switch (result.Status) // { // case IntegrationStatus.Unknown: // case IntegrationStatus.Success: // result.Status = this.WasSuccessful ? IntegrationStatus.Success : IntegrationStatus.Failure; // break; // } // } //} public void Run(IIntegrationResult result) { //return Path.Combine(result.ArtifactDirectory, string.Format(logFilename, LogFileId)); //delete log file from last run //result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : // string.Format("Executing Nant :BuildFile: {0} Targets: {1} ", BuildFile, string.Join(", ", Targets))); var processResult = _executor.Execute(CreateProcessInfo(result)); result.AddTaskResult(new ProcessTaskResult(processResult)); //for this run add the results of execution //check if an output XML file was created (i.e. the build runner actually ran) //if (File.Exists(outputFile)) //{ // result.AddTaskResult(new FileTaskResult(outputFile)); //} //else //{ // Log.Warning(string.Format("MbUnit test output file {0} was not created", outputFile)); //} //if (processResult.TimedOut) // throw new BuilderException(this, "NAnt process timed out (after " + BuildTimeoutSeconds + " seconds)"); //return !processResult.Failed; //var process = new Process(); //process.StartInfo.FileName = Executable; //process.StartInfo.Arguments = CreateArgumentString(); ////redirect to a stream so we can parse it and display it //process.StartInfo.CreateNoWindow = true; //process.StartInfo.UseShellExecute = false; //process.StartInfo.ErrorDialog = false; //if (!String.IsNullOrEmpty(BaseDirectory)) // process.StartInfo.WorkingDirectory = BaseDirectory; //process.Start(); }
protected ProcessResult Execute(ProcessInfo processInfo) { processInfo.TimeOut = Timeout.Millis; ProcessResult result = executor.Execute(processInfo); if (result.TimedOut) { throw new CruiseControlException("Source control operation has timed out."); } else if (result.Failed) { throw new CruiseControlException(string.Format("Source control operation failed: {0}. Process command: {1} {2}", result.StandardError, processInfo.FileName, processInfo.Arguments)); } else if (result.HasErrorOutput) { Log.Warning(string.Format("Source control wrote output to stderr: {0}", result.StandardError)); } return(result); }
public void KillProcessesForProjectKillsAProcess() { var fileSystemMock = InitialiseFileSystemMockForExecute(); var info = new ProcessInfo("sleeper"); var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object }; var projectName = "aProject"; var thread = new Thread( () => executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt")); thread.Start(); var started = SpinWait.SpinUntil(() => Process.GetProcessesByName("sleeper").Length > 0, TimeSpan.FromSeconds(5)); Assert.IsTrue(started); ProcessExecutor.KillProcessesForProject(fileSystemMock.Object, projectName); var stopped = SpinWait.SpinUntil(() => Process.GetProcessesByName("sleeper").Length == 0, TimeSpan.FromSeconds(5)); Assert.IsTrue(stopped); }
/// <summary> /// Tries to run. /// </summary> /// <param name="info">The info.</param> /// <param name="result">The result.</param> /// <returns></returns> /// <remarks></remarks> protected ProcessResult TryToRun(ProcessInfo info, IIntegrationResult result) { buildProgressInformation = result.BuildProgressInformation; try { // enable Stdout monitoring executor.ProcessOutput += ProcessExecutor_ProcessOutput; return(executor.Execute(info)); } catch (IOException e) { throw new BuilderException( this, string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unable to execute: {0} {1}\n{2}", info.FileName, info.PublicArguments, e), e); } finally { // remove Stdout monitoring executor.ProcessOutput -= ProcessExecutor_ProcessOutput; } }