Using Python to Execute a C or FORTRAN Program (Windows)

Gib Bogle g.bogle at auckland.no.spam.ac.nz
Mon Dec 21 18:31:21 EST 2009


W. eWatson wrote:
> Mensanator wrote:
>> On Dec 14, 8:14�pm, "W. eWatson" <wolftra... at invalid.com> wrote:
>>> I think Python is capable of executing a compiled C or FORTRAN program,
>>
>> Sure, if it was compiled to an .exe file.
>>
>>> and maybe even getting some parameters passed back.
>>
>> Sure, if the program prints to stdout.
>>
>>> Does anyone have a
>>> example of how this might be done? I'm running under Win XP Pro.
>>
>> Here's one. The test program is factor.exe (included in
>> the MIRACL library). I recompiled it (factor!.exe) to
>> produce consitent output.
> ...
> Thanks. OK, I think I can follow that. I want to pass it along to 
> someone who either missed this possibility in some coding, ignored it, 
> or felt more comfortable about just writing the whole program from 
> scratch in c++. His program was originally written in Python, but a new 
> hardware device (capture card) had no good interface with Python, so he 
> wrote it in C++, which does. From my knowledge of the Python program 
> before the entry of c++, it seems he could have farmed out the hardware 
> interface in much the same way he had done it before with a capture card 
> well know to him.
> 
> Would the same Python interface work for a compiled C++ program?

I am working on a Python UI (PyQt4) to a Fortran program.  The approach I've 
taken is to build the Fortran code as a DLL (or .so).  Python can load the 
library and call a procedure that initiates execution.  I'm using sockets to 
pass data of different types back to the Python program.  This is a work in 
progress, and I'm learning Python as we go.



More information about the Python-list mailing list