<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7650.5">
<TITLE>[Python.NET] How to run a .py file from C#</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">Hi,</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I'm a newbie in C# and python and try to run a .py file from a C# program.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I tried the same thing from a C++ program using PyRun_SimpleFile and in the console, I could see the python execution (the print from python).</FONT></P>

<P><FONT SIZE=2 FACE="Arial">Using Python.Runtime.dll from Python.NET, I saw that such a fonction is not available, and should use PythonEngine.ImportModule and PythonEngine.RunString or PythonEngine.RunSimpleString. The thing is that it only works for a command written over one line, but if I have a &quot;def&quot; (which is written over several lines), the RunString doesn't work any more... So how can I run the whole file, and not only line by line ?</FONT></P>

<P><FONT SIZE=2 FACE="Arial">By the way, what does exactly the ImportModule function ? Maybe the .py file is already executed but I can't see it ? Is there a way to get the output and display it in the console ?<BR>
<BR>
Thanks for you answer</FONT>
</P>
<UL>
<P><B><FONT COLOR="#FF0000" SIZE=1 FACE="Book Antiqua">__</FONT><FONT SIZE=1 FACE="Book Antiqua"> </FONT><FONT COLOR="#000080" SIZE=1 FACE="Book Antiqua">Sylvie LIVERNAIS</FONT><FONT SIZE=1 FACE="Book Antiqua"> </FONT><FONT COLOR="#FF0000" SIZE=1 FACE="Book Antiqua">___________</FONT></B>

<BR><FONT COLOR="#000080" SIZE=1 FACE="Book Antiqua">Applications Cartes à Puce</FONT>

<BR><FONT COLOR="#000080" SIZE=1 FACE="Book Antiqua">EID</FONT>

<BR><B><FONT COLOR="#000080" SIZE=2 FACE="Wingdings">(<SPAN LANG="nl"></SPAN></FONT></B><SPAN LANG="nl"></SPAN><SPAN LANG="nl"></SPAN><SPAN LANG="nl"><FONT COLOR="#000080" SIZE=2 FACE="Book Antiqua"> : +33 (0) 388 14 28 75</FONT></SPAN><SPAN LANG="fr"></SPAN><SPAN LANG="fr"></SPAN><SPAN LANG="fr"></SPAN>
</P>
</UL>
</BODY>
</HTML>