[Tutor] create a wrapper for a C program
stefan_ml at behnel.de
Wed Apr 7 08:09:47 CEST 2010
anjali nair, 06.04.2010 17:17:
> I am new to python. My doubt is related to wrapping a C program with a
> python script.. I am running Netperf for Network Performance Benchmarking.
> The code is written in C and has an associated Makefile. I thought of
> writing a Python script which should be able to run Netperf with the
> associated arguments on executing it. Do I need to go for SWIG? I tried
> invoking by using subprocess, but that did not work.
"netperf" is a command line tool, so subprocess is the way to go. Note that
"did not work" isn't a very complete problem description, so if you want
advice on how to solve the problem at hand, please provide the code you
tried and the exact error output that you got.
If you really want to write a C-level wrapper for the tool, you should
first make sure that there is 1) an exported library that you can interface
with, and either 2a) more functionality in the library than in the command
line tool, or 2b) functionality in the library where you can benefit from
very fast calling. If the major work happens inside of the tool, and it
provides the functionality you need through its command line interface,
writing a C-level wrapper for it is almost certainly not worth it.
BTW, SWIG isn't a particularly good way of writing a Python wrapper for a C
program (unless you want to generate wrappers for some other languages at
the same time).
More information about the Tutor