title: Shell Exec StdOut to Existing console
body: <p>So I know how to use <code>wscript</code> to launch a console, send and read from it, </p>
  
  <p>but what about doing this with an existing console window?  </p>
  
  <p>(<em>I have the functions divided up in such a way as I can use them separately for other reasons)</em></p>
  
  <p>How can I send and receive lines from a console I've previously created?   </p>
  
  <pre><code>Startconsole:
      LaunchConsole(showconsole)  ;display console based on user settings
      DllCall("AttachConsole", "UInt", conWinPID)
  return
  
  LaunchConsole(hideconsole=0){
      global
      if(hideconsole){
          hideconsole := "hide"
      }
      Run %ComSpec% /K cd /D c:\test, c:\test, %hideconsole%, conWinPID
      winwait, ahk_pid %conWinPID%
      winsettitle, ahk_pid %conWinPID%,,My Console Title
  }
  
  ConsoleCommand(whatcommand){
      global myEdit
      oExec := ComObjCreate("WScript.Shell").Exec(whatcommand)
      While, !oExec.StdOut.AtEndOfStream
          result := oExec.StdOut.ReadAll()
          guicontrol,, myEdit, %result%
      Return, result
  }
  
  CloseConsole:
      DllCall("FreeConsole")
      winclose, ahk_pid %conWinPID%   
  return
  </code></pre>
  
  <p>So I want to do this:</p>
  
  <pre><code>gosub, StartConsole
  ConsoleCommand("ping google.com -n 1")
  ConsoleCommand("ping somewhereelse.com -n 1")
  gosub, CloseConsole
  </code></pre>
  
  <p>The lines from the console should display in both my edit control AND in the console that I created in <code>LaunchConsole</code> rather than the one I am created in the wscripting.  I need to make the wscript work with my console.</p>
  
  <p><em>[update]</em></p>
  
  <p>I think it actually <em>might be</em> using that console - it's just that the commands I send via wscript don't display in the console, AND whatever I type in the console is not fed back into the script.</p>