[Tutor] Executing a C Program from RH Linux in Python for Win

Alan Gauld alan.gauld at btinternet.com
Wed Mar 18 19:00:39 CET 2009

"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote

> The Subject contains the interest here. Can it be done?

A C program is compiled into a binary executable complete
with link loader. The executable is not portable across operating
systems (nor hardware architectures in most cases)

> I think it this case it requires executing the program
> command line with parameters then executing it?

Yes and that can be done via the Popen class in the subprocess
module. So your python program can launch an executable and
read/write to stdout/in

Alternatively you can launch a GUI program and access it via
technologies such as COM in Windows. Other OS/Desktop
environments have other hooks - eg Applescript can often be
used on MacOS.

> How dependent upon the C compiled code is this? That is,
> I would think various distributions of Linux might produce
> different executable code.

No the compiled code runs (or can run) on any distribution of
Linux. The distributions vary in where they store system files,
which packages are included/installed as standard and the
admin tools they provide. But the underlying OS is essentially
the same for all of them.

> The too I would want to do this in Win. Is there, in fact, some
> Linux environment in Win that would allow me to test its executable?

You can run Linux on a virtual machine inside Windows. VMWare is
one route to this. Or you might be able to use cygwin to produce a
windows application running using cygwin (a set of Linux like
libraries for Windows). The formner alloows you to run the actual
Linux executable file, the latter allows you to recompile the C code
to run under Windows. Depends what suits you best.


Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list