Hi,<br><br><div class="gmail_quote">2010/2/17 stephen <span dir="ltr"><<a href="mailto:stephen@blackroses.com">stephen@blackroses.com</a>></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 "read" for STDIN and "write" 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("print 'test'") 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("testing"); 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'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't "get handles"</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("stdin") and "stdout" accordingly. However I</div>
<div>don't actually see where this translates into the Python runtime checking with the C-runtime for the "real" handles to STDIN and STDOUT. I dont ever see the Python runtime "ask the system" 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's important that your program and python use the same C runtime library (MSVCR90.dll for python 2.6), otherwise "stdout" refers to different things.</div>
</div><br>-- <br>Amaury Forgeot d'Arc<br>