[Tutor] Executing a C Program from RH Linux in Python for Win
Martin Walsh
mwalsh at mwalsh.org
Thu Mar 19 05:27:19 CET 2009
Wayne Watson wrote:
> If you can execute a C program compiled on a Linux with SWIG, then
> that's what I'm looking for. There's really no RH dependency according
> to the above posts. If it were compiled on Debian or Ubuntu, it appears
> it would not make any difference. That is, one could execute a RH
> executable from C on Ubuntu.
Yeah, probably -- if it's a static build, or if the dependencies
(required libraries/versions) are installed, assuming the program has
dependencies. But, I suppose we may be drifting a bit OT.
>
> Is there a simple example of this in action from a Python program and
> some small C Linux executable program?
http://docs.python.org/library/subprocess.html
The subprocess module is commonly recommended for this type of task (as
opposed to os.system, etc). In fact, I believe Alan already suggested it
in this thread. And speaking of ... Alan's tutorial has several very
good examples of using the subprocess module (OS topic under
Manipulating Processes).
http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm
---
I'll hazard a wild guess that you don't really want SWIG based on your
original question, and subsequent comments. IIUC, SWIG is intended to
ease the creation of a python wrapper (extension module) for existing
C/C++ code. And, I'm not sure you've given enough information about the
C program to determine if SWIG would be useful. Regardless, I suggest
you get a feel for running an external program using python first.
HTH,
Marty
More information about the Tutor
mailing list