Hi,<br><br><div class="gmail_quote">2010/2/17 stephen <span dir="ltr">&lt;<a href="mailto:stephen@blackroses.com">stephen@blackroses.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello, <div><br></div><div>THE PROBLEM:<br>
<div>  I am having a problem that I have seen asked quite a bit on the web, with little to no follow up.</div><div>The problem is essentially this. When embedding (LoadLibraryA()) the python interpreter dll</div><div>in a non-windows application the developer must first create a console for python to do output/input with.</div>

<div>I properly initialize the CRT and AllocConsole() to do this. I then GetSTDHandle() for stdin and stdout accordingly</div><div>and open those handles with the requisite flags &quot;read&quot; for STDIN and &quot;write&quot; for stdout. This all works great</div>

<div>and is then verified and tested to work by printf() and fgets(). This issue however happens when attempting</div><div>to PyRun_InteractiveLoop() and PyRun_SimpleString(). A PyRun_SimpleString(&quot;print &#39;test&#39;&quot;) displays nothing in my </div>

<div>freshly allocated console window. Similarly a PyRun_InteractiveLoop(stdin, NULL); yields nothing either even though</div><div>the line printf(&quot;testing&quot;); directly ahead of it works just fine. Does anyone have insight on how I can make this work</div>

<div>with the freshly allocated console&#39;s stdin/stdout/stderr?</div><div><br></div><div>SPECULATION:</div><div>That is the question, so now on to the speculation. I suspect that something in the python runtime doesn&#39;t &quot;get handles&quot;</div>

<div>correctly for STDIN and STDOUT upon initialization. I have perused the source code to find out exactly how this is done</div><div>and I suspect that it starts in PyInitializeEx with calls to PySys_GetObject(&quot;stdin&quot;) and &quot;stdout&quot; accordingly. However I</div>

<div>don&#39;t actually see where this translates into the Python runtime checking with the C-runtime for the &quot;real&quot; handles to STDIN and STDOUT. I dont ever see the Python runtime &quot;ask the system&quot; where his handles to STDIN and STDOUT are.</div>
</div></blockquote><div><br></div><div>Are you using the same compiler as the one used to compile Python? It&#39;s important that your program and python use the same C runtime library (MSVCR90.dll for python 2.6), otherwise &quot;stdout&quot; refers to different things.</div>
</div><br>-- <br>Amaury Forgeot d&#39;Arc<br>