Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string GetExecutableOutput(string sExecute, string sParams, out int iExitCode)
- {
- iExitCode = -999;
- StringBuilder builder = new StringBuilder();
- builder.Append("Results from " + sExecute + " " + sParams + "\r\n\r\n");
- try
- {
- string str;
- Process process = new Process {
- StartInfo = { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = false, CreateNoWindow = true, FileName = sExecute, Arguments = sParams }
- };
- process.Start();
- while ((str = process.StandardOutput.ReadLine()) != null)
- {
- str = str.TrimEnd(new char[0]);
- if (str != string.Empty)
- {
- builder.Append(str + "\r\n");
- }
- }
- iExitCode = process.ExitCode;
- process.Dispose();
- }
- catch (Exception exception)
- {
- builder.Append("Exception thrown: " + exception.ToString() + "\r\n" + exception.StackTrace.ToString());
- }
- builder.Append("-------------------------------------------\r\n");
- return builder.ToString();
- }
Add Comment
Please, Sign In to add comment