title: How to capture display output from a command prompt in Windows at any moment?
body: <p>I'm tring to capture de information shown in a command prompt (cmd window) at a specific moment and send it to a text file.</p>
  
  <p>I have an app in C/C++ that is launched by a batch script like this:</p>
  
  <pre><code>c:\myProgramInC.exe
  echo "Ending with error"
  PAUSE
  </code></pre>
  
  <p>myProgramInC.exe is always running (with an infinite loop) so if my script gets to the echo command it means my app ended with an abend.</p>
  
  <p>What I want to get is the previous lines before the end execution of the script since my myProgramInC.exe always prints info about what is going on and it would be very useful to see what it was happening when the error ocurred. Something like this</p>
  
  <pre><code>c:\myProgramInC.exe
  **** Execution of process to get te previous N lines in the command prompt ****
  echo "Ending with error"
  PAUSE
  </code></pre>
  
  <p>I know the cmd window have a buffer and I've been thinking to capture all of this data from such buffer. It is any way to get this info as text to store it in a file?</p>
  
  <p>I'v been trying with something more professional shuch as to make a dump of the memory with ProcDump but since I have various myProgramInC.exe running at the same time (each one stored in a different location) I just get the message "Multiple processes match the specified name." and the rest of the options are just not useful for me since my app doesn't get unresponsive, it simply ends.</p>
  
  <p>Any ideas?</p>