<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
<span class="Apple-style-span" style="color: rgb(42, 42, 42); background-color: rgb(255, 255, 255); "><font class="Apple-style-span" size="2" face="Tahoma">> Is the `code` module (<a href="http://docs.python.org/library/code.html" target="_blank" style="line-height: 17px; text-decoration: underline; color: rgb(0, 104, 207); cursor: pointer; ">http://docs.python.org/library/code.html</a>) an insufficiently exact copy of an interpreter for you?</font></span><div><span class="Apple-style-span" style="color: rgb(42, 42, 42); background-color: rgb(255, 255, 255); "><font class="Apple-style-span" size="2" face="Tahoma"><br></font></span></div><div><span class="Apple-style-span" style="color: rgb(42, 42, 42); background-color: rgb(255, 255, 255); "><font class="Apple-style-span" size="2" face="Tahoma">The problem isn't really to emulate the behavior of the interpreter as to obtain the result of the execution as a string in c++. </font></span></div><div><font class="Apple-style-span" color="#2a2a2a" size="2" face="Tahoma">The code module doesn't seem to help with this matter.</font></div><div><font class="Apple-style-span" color="#2a2a2a" size="2" face="Tahoma"><br></font></div><div><font class="Apple-style-span" size="2" face="Tahoma"><font class="Apple-style-span" color="#2a2a2a">> </font><span class="Apple-style-span" style="color: rgb(42, 42, 42); line-height: 17px; background-color: rgb(255, 255, 255); ">I assume you could simply use PyFile_FromFd?</span></font></div><div><span class="Apple-style-span" style="color: rgb(42, 42, 42); line-height: 17px; background-color: rgb(255, 255, 255); "><font class="Apple-style-span" size="2" face="Tahoma"><br></font></span></div><div><span class="Apple-style-span" style="color: rgb(42, 42, 42); line-height: 17px; background-color: rgb(255, 255, 255); "><font class="Apple-style-span" size="2" face="Tahoma">According to the documentation using PyFile_FromFd seems unadvised, but I'll give it a try.</font></span></div><div><span class="Apple-style-span" style="color: rgb(42, 42, 42); line-height: 17px; background-color: rgb(255, 255, 255); "><font class="Apple-style-span" size="2" face="Tahoma"><br></font></span></div><div><span class="Apple-style-span" style="color: rgb(42, 42, 42); line-height: 17px; background-color: rgb(255, 255, 255); "><span class="Apple-style-span" style="line-height: normal; "><pre style="line-height: 17px; white-space: normal; "><font class="Apple-style-span" size="2" face="Tahoma">> The more elegant solution might be to create custom Python file-like<br style="line-height: 17px; ">> objects for std{in,out,err} that communicate directly with your application.</font></pre></span></span></div><div><font class="Apple-style-span" color="#2a2a2a" size="2" face="Tahoma">I thought about this, but I need the console window to be non-modal and I'm afraid that replacing stdin with</font></div><div><font class="Apple-style-span" color="#2a2a2a" size="2" face="Tahoma">a custom file-like object would cause a blocking call. Executing python in a second thread would solve this problem</font></div><div><font class="Apple-style-span" color="#2a2a2a" size="2" face="Tahoma">but our application isn't multi-threaded and executing python in another thread causes errors.</font></div><div><font class="Apple-style-span" color="#2a2a2a" size="2" face="Tahoma"><br></font></div><div><font class="Apple-style-span" color="#2a2a2a" face="Tahoma" size="2">Maybe I could use a file-like object to communicate the results to my c++ application and use the code </font></div><div><font class="Apple-style-span" color="#2a2a2a" face="Tahoma" size="2">module to execute code only when the c++ application needs it.</font></div><div><font class="Apple-style-span" color="#2a2a2a" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" color="#2a2a2a" face="Tahoma" size="2">Thanks a lot for the tips, have a nice day.</font></div><div><font class="Apple-style-span" color="#2a2a2a" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" color="#2a2a2a" face="Tahoma" size="2">F.L.</font></div>                                    </div></body>
</html>