title: Error while redirecting console output to TextBox , WPF application
body: <p>I am trying to redirect the console output to my WPF application TextBox.
  But I am getting below exception </p>
  
  <pre><code>"The system connot find the file specified"
  </code></pre>
  
  <p>Here is my code</p>
  
  <pre><code>{
      string rootDir = sourcePath; 
      string command = CAConstants.CPPCheckCommand + sourcePath + " 2&gt; " + rootDir + CAConstants.FileSeparator + CAConstants.CPPCHECKFileName;
  
      using (proc = new Process())
      {
          // set environment variables
          string pathVar = proc.StartInfo.EnvironmentVariables[CAConstants.ENV_Path];
          string cppcheckPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) +  CAConstants.CPPCheckRootDir;
          proc.StartInfo.EnvironmentVariables[CAConstants.ENV_Path] = pathVar + cppcheckPath + ";";
  
          //set process name
          proc.StartInfo.FileName = command;
  
          proc.StartInfo.UseShellExecute = false;
  
          // set up output redirection
          proc.StartInfo.RedirectStandardOutput = true;
          proc.StartInfo.RedirectStandardError = true;
          proc.EnableRaisingEvents = true;
          proc.StartInfo.CreateNoWindow = true;
  
          // see below for output handler
          proc.ErrorDataReceived += proc_DataReceived2;
          proc.OutputDataReceived += proc_DataReceived2;
  
          proc.Start();   // Getting error at this line
  
          proc.BeginErrorReadLine();
          proc.BeginOutputReadLine();
  
          //proc.WaitForExit();
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>void proc_DataReceived2(object sender, DataReceivedEventArgs e)
  {
      // output will be in string e.Data
      if (!String.IsNullOrEmpty(e.Data))
      {
          if (!logsTextBox.Dispatcher.CheckAccess())
          {
              // Called from a none ui thread, so use dispatcher
              ShowLoggingDelegate showLoggingDelegate = new ShowLoggingDelegate(ShowLogging);
              logsTextBox.Dispatcher.Invoke(DispatcherPriority.Normal, showLoggingDelegate, e.Data);
          }
          else
          {
              // Called from UI trhead so just update the textbox
              ShowLogging(e.Data);
          };
      }
  }
  
  private delegate void ShowLoggingDelegate(string text);
  
  private void ShowLogging(string text)
  {
      logsTextBox.AppendText(text);
      logsTextBox.ScrollToEnd();
  }
  </code></pre>
  
  <p>I found this links, <a href="https://stackoverflow.com/questions/415620/redirect-console-output-to-textbox-in-separate-program">Redirect console output to textbox in separate program</a></p>
  
  <p>but not able to resolve my error</p>
  
  <p>this is my command</p>
  
  <pre><code>cppcheck -v --enable=all --xml C:\\Test_projects\\52 2&gt; C:\\Test_projects\\52\\cppcheck.xml
  </code></pre>
  
  <p>getting error when I am starting process.</p>
  
  <p>and when I run this on command prompt, its working fine.
  what I am missing?
  Any help.</p>