Advertisement
Guest User

Process.StandardOutput.ReadLine

a guest
Apr 14th, 2011
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.49 KB | None | 0 0
  1. StringBuilder errS = new StringBuilder();
  2.                 Boolean errYes = false;
  3.                 Thread runProc = new Thread(() =>
  4.                     {
  5.                         Process reCache = new Process();
  6.                         try
  7.                         {
  8.                             this.UIThread(() =>
  9.                             {
  10.                                 panel2.Location = new Point(0, 0);
  11.                                 panel2.Enabled = true;
  12.                                 panel2.Visible = true;
  13.                             });
  14.  
  15.                             reCache.StartInfo.FileName = copiedFileLoc;
  16.                             reCache.StartInfo.RedirectStandardOutput = true;
  17.                             reCache.StartInfo.UseShellExecute = false;
  18.                             reCache.StartInfo.CreateNoWindow = true;
  19.                             reCache.Start();
  20.                             StreamReader localSW = reCache.StandardOutput;
  21.                             string aLine = "";
  22.  
  23.                             while ((aLine = reCache.StandardOutput.ReadLine()) != null)
  24.                             {
  25.                                
  26.                                     if (
  27.                                         (aLine.ToLower().Contains("error")) ||
  28.                                         (aLine.ToLower().Contains("error:"))
  29.                                         )
  30.                                     {
  31.                                         if (!errYes)
  32.                                         {
  33.                                             errYes = true;
  34.                                         }
  35.                                         errS.Append(aLine + Environment.NewLine);
  36.  
  37.                                     }
  38.                                     this.UIThread(() =>
  39.                                     {
  40.                                         textBox7.Text += aLine + Environment.NewLine;
  41.                                     });
  42.                                
  43.                             }
  44.  
  45.                            
  46.                             reCache.WaitForExit();
  47.                             if (errYes)
  48.                             {
  49.                                 MessageBox.Show("Errors may have occured. Note that SQL errors are \"expected\"" +
  50.                                                 Environment.NewLine + Environment.NewLine +
  51.                                                 errS.ToString(),
  52.                                                 "Possible Errors",
  53.                                                 MessageBoxButtons.OK,
  54.                                                 MessageBoxIcon.Warning);
  55.                             }
  56.  
  57.                         }
  58.                         catch (SecurityException secEx)
  59.                         {
  60.                             MessageBox.Show("There was a security/access issue with this file." +
  61.                                             Environment.NewLine +
  62.                                             secEx.Message +
  63.                                             Environment.NewLine + Environment.NewLine +
  64.                                             secEx.StackTrace,
  65.                                             "Security/Access error",
  66.                                             MessageBoxButtons.OK,
  67.                                             MessageBoxIcon.Exclamation);
  68.                             return;
  69.                         }
  70.                         catch (Exception ex)
  71.                         {
  72.                             MessageBox.Show("ERROR: " + ex.Message + Environment.NewLine + Environment.NewLine +
  73.                                             ex.StackTrace,
  74.                                             "ERROR",
  75.                                             MessageBoxButtons.OK,
  76.                                             MessageBoxIcon.Error);
  77.                             return;
  78.                         }
  79.                         finally
  80.                         {
  81.                             reCache.Dispose();
  82.                             this.UIThread(() =>
  83.                                 {
  84.                                     panel2.Location = new Point(1400, 1400);
  85.                                     panel2.Enabled = false;
  86.                                     panel2.Visible = false;
  87.  
  88.                                     LoadorReLoad(true);
  89.                                 });
  90.                         }
  91.  
  92.                     });
  93.                 runProc.Start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement