public bool Run() { m_id++; if (WaitEnd) { bool log = ((NoDebugLog == false) && (Engine.Instance != null) && (Engine.Instance.Storage != null) && (Engine.Instance.Storage.GetBool("log.level.debug"))); if (log) { string message = "Shell(" + m_id + ") of '" + Path + "'"; if (Arguments.Count > 0) { message += ", " + Arguments.Count.ToString() + " args: "; foreach (string arg in Arguments) { message += "'" + arg + "';"; } } message = Utils.RegExReplace(message, "[a-zA-Z0-9+/]{30,}=", "{base64-omissis}"); Engine.Instance.Logs.Log(LogType.Verbose, message); } int startTime = Environment.TickCount; Platform.Instance.ShellSync(Path, Arguments.ToArray(), out StdOut, out StdErr, out ExitCode); int endTime = Environment.TickCount; if (log) { int deltaTime = endTime - startTime; string message = "Shell(" + m_id + ") done in " + deltaTime.ToString() + " ms"; message += ", exit: " + ExitCode.ToString(); if (StdOut != "") { message += ", out: '" + StdOut + "'"; } if (StdErr != "") { message += ", err: '" + StdErr + "'"; } message = Utils.RegExReplace(message, "[a-zA-Z0-9+/]{30,}=", "{base64-omissis}"); Engine.Instance.Logs.Log(LogType.Verbose, message); } if (ExceptionIfFail) { if (ExitCode != 0) { if (StdErr != "") { throw new Exception(StdErr); } else { throw new Exception(Messages.Failed); } } } return(ExitCode == 0); } else { Platform.Instance.ShellASync(Path, Arguments.ToArray()); return(true); } }
public static string ShellPlatformIndipendentEx(string FileName, string Arguments, string WorkingDirectory, bool WaitEnd, bool ShowWindow, bool noDebugLog) { try { int startTime = Environment.TickCount; Process p = new Process(); p.StartInfo.Arguments = Arguments; if (WorkingDirectory != "") { p.StartInfo.WorkingDirectory = WorkingDirectory; } p.StartInfo.FileName = FileName; if (ShowWindow == false) { //#do not show DOS window p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; } if (WaitEnd) { p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; } p.Start(); if (WaitEnd) { string Output = p.StandardOutput.ReadToEnd() + "\n" + p.StandardError.ReadToEnd(); p.WaitForExit(); Output = Output.Trim(); if (noDebugLog == false) // Avoid recursion { if ((Engine.Instance != null) && (Engine.Instance.Storage != null) && (Engine.Instance.Storage.GetBool("log.level.debug"))) { int endTime = Environment.TickCount; int deltaTime = endTime - startTime; string message = "Shell of '" + FileName + "','" + Arguments + "' done sync in " + deltaTime.ToString() + " ms, Output: " + Output; message = Utils.RegExReplace(message, "[a-zA-Z0-9+/]{30,}=", "{base64-omissis}"); Engine.Instance.Logs.Log(LogType.Verbose, message); } } return(Output); } else { return(""); } } catch (Exception E) { return("Error:" + E.Message); // 2.8 } }