public void ExecuteCommand(object commandVal) { try { CommandElements commandVals = (CommandElements)commandVal; Process process = new Process(); if (commandVals.WorkingFolder != null) { process.StartInfo.WorkingDirectory = commandVals.WorkingFolder; } process.StartInfo.FileName = commandVals.ExecuterFilePath; process.StartInfo.Arguments = commandVals.Arguments; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardError = true; mCommandOutputBuffer = string.Empty; mCommandOutputErrorBuffer = string.Empty; process.OutputDataReceived += (proc, outLine) => { AddCommandOutput(outLine.Data); }; process.ErrorDataReceived += (proc, outLine) => { AddCommandOutputError(outLine.Data); }; process.Exited += Process_Exited; Console.WriteLine("--Staring process"); process.Start(); Stopwatch stopwatch = Stopwatch.StartNew(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); int maxWaitingTime = 1000 * 60 * 60;//1 hour process.WaitForExit(maxWaitingTime); Console.WriteLine("--Process done"); stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= maxWaitingTime) { GingerAction.AddError("Command processing timeout has reached!"); } } catch (Exception ex) { GingerAction.AddError("Failed to execute the command, Error is: '{0}'" + ex.Message); Console.Write(ex.Message); } finally { GingerAction.AddExInfo("--Exiting execute command"); } }
private CommandElements PrepareCommand() { string Arguments = string.Empty; CommandElements command = new CommandElements(); command.ExecuterFilePath = @"ruby"; command.WorkingFolder = Path.GetDirectoryName(RubyScriptPath); Arguments += string.Format("\"{0}\"", RubyScriptPath); if (RubyPrameters != null) { foreach (RubyPrameters rp in RubyPrameters) { Arguments += " " + rp.Value; } } command.Arguments = Arguments; return(command); }
public void Execute() { Console.WriteLine("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Execution Started %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); try { switch (ExecutionMode) { case eExecutionMode.ScriptPath: CommandElements command = new CommandElements(); command = PrepareCommand(); ExecuteCommand(command); ParseCommandOutput(); break; } } catch (Exception ex) { GingerAction.AddError("Error while executing script : " + ex.ToString()); } }