title: C++ Save console output to a text file before quit WINAPI ( No MFC )
body: <p>I am trying to get my program to log the output of a console application to a text file before it quits. This is a GUI program which launches the console application (tool.exe). The problem is that I am using CTRL + C to quit the console application. This console application cant be altered either. I have tried a few ways of doing this but none have seemed to work ( tool.exe > output.txt ).</p>
  
  <p>Can anyone point me in the right direction of which approach to take ? It would be greatly appreciated.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The file is created but it is empty and does not receive any data. The thing I am after noticing though is if I run the tool from the command line myself, it will work. Eg. <code>c:\&gt;tool.exe &gt; output.txt</code> However this is not working when its executed from my GUI application. </p>
  
  <p>Here is the code I am using to execute the tool:</p>
  
  <pre><code>    strcpy (tool, "\" start /D \"");
      strcat (tool, toolLocation);
      strcat (tool, "\" tool.exe &gt; output.txt\"");
      system (tool);
  </code></pre>
  
  <p>This will run tool.exe and create output.txt fine but will not output anything to the file.</p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>I think what is actually happening is that because I am using <code>start</code> , the <code>&gt;output.txt</code> is outputing <code>start</code> instead of <code>tool.exe</code>. This would explain why it creates the empty file. Start is just running a fresh command line which is then running <code>tool.exe</code>. The problem is, how do I get around this issue now ?</p>