title: How to get console output data into command prompt?
body: <p>I have a Windows based application. I made it to work in for both <code>GUI Mode</code> and <code>Console Mode</code>. In <code>GUI mode</code> or <code>Console mode</code> I am attaching a <code>Console</code> by using <code>AttachConsole()</code> to bring up output print statements to the console. Now the challenge is, I don't need new console to come up while I am using it in <code>console mode</code> or from <code>Command prompt</code>.
  Suppose from command prompt, I am running it as </p>
  
  <p><code>d:\Project path &gt; MyApp.exe consolemode</code> <code>**Enter**</code></p>
  
  <p>Then it brings up the another console, because of <code>Attachconsole()</code>. Now when I disable the <code>AttachConsole()</code> it does not bring up the new console and it does not show the output in command prompt too. But my requirement is to show the output in <code>commandprompt</code> instead of bringing up new console while executing from comamnd prompt. </p>
  
  <pre><code>Myapp.cpp
  Winmain()
  {
  ....
  ...
  AttachConsole();
  cout &lt;&lt; "Console Attached \n";
  // Some more output
  }
  </code></pre>
  
  <p>So, when i run the <code>myapp.exe</code> from command promt
  <code>d:\Project path &gt; MyApp.exe consolemode</code> <code>**Enter**</code>
  it attaches a <code>new console</code> and prints the output in new console window. Now my requirement is I need to disable <code>AttachConsole();</code> and wanted to see the output in the command prompt.</p>
  
  <pre><code>Myapp.cpp
  Winmain()
  {
  ....
  ...
  //AttachConsole(); //Now I an disabling console
  cout &lt;&lt; "Console Attached \n";
  // Some more output
  }
  </code></pre>
  
  <p>If you look at the code above I have disabled the <code>AttachConsole()</code>. Now want when I do,</p>
  
  <p><code>d:\Project path &gt; MyApp.exe consolemode</code> <code>**Enter**</code>
  The output will come in comamnd prompt. like below</p>
  
  <pre><code>d:\Project path &gt; MyApp.exe consolemode **Enter**
  Console Attached
  ....
  ...
  d:\Project path &gt;
  </code></pre>
  
  <p>Please help me</p>