Execute C code through Python

E

Ernesto

What's the easiest and quickest way to execute a compiled C "command
line interface" program THROUGH Python?
 
D

Diez B. Roggisch

Ernesto said:
What's the easiest and quickest way to execute a compiled C "command
line interface" program THROUGH Python?

I don't know what you mean by THROUGH. But the subprocess, popen2 and
os-modules deal with calling other programs. Try them in that order.

Diez
 
E

Ernesto

Thanks. Can anyone provide an example of using *subprocess* to run
helloWorld.C through the python interpreter.
 
F

Fredrik Lundh

Ernesto said:
Thanks. Can anyone provide an example of using *subprocess* to run
helloWorld.C through the python interpreter.

compile helloWorld, and run:

import subprocess
subprocess.call("helloWorld")

(any special reason why you couldn't figure this out yourself, given the
example provided by gsteff ?)

</F>
 
G

Grant Edwards

Thanks. Can anyone provide an example of using *subprocess* to run
helloWorld.C through the python interpreter.

No. You can't run a .C file. You can run a .exe file (I'm
guessing you're using Windows based on the question).
 
S

Steve Holden

Grant said:
Yow! That's two in one day, what do I win?
If my experience is anything to go by it just means there won't be a
weekly URL this week :)

regards
Steve
 
E

Ernesto

Fredrik said:
compile helloWorld, and run:

import subprocess
subprocess.call("helloWorld")

(any special reason why you couldn't figure this out yourself, given the
example provided by gsteff ?)

</F>

There is a reason (though it is not special). I'm new to Python. I
looked at all the documentation on subprocess, as well as popen. I
couldn't figure it out, so I thought an example (which I thank you for
providing) would help me along (which it did). Is there a special
reason for you having a problem with me asking for help? I thought
that's what this group is for.
 
F

Fredrik Lundh

Ernesto said:
There is a reason (though it is not special). I'm new to Python. I
looked at all the documentation on subprocess, as well as popen. I
couldn't figure it out, so I thought an example (which I thank you for
providing) would help me along (which it did).

as I noted in the part of my reply that you didn't read, the person you replied to
(gsteff) also provided an example. Since his post didn't contain any other text, I
did find it a bit strange that you missed that part of his message, but still managed
to reply to it.

</F>
 
E

Ernesto

So i generated the .exe file "myFile.exe"

This is a Windows - text based application. Right now, when I run:

import subprocess
subprocess.call("myFile")

the application starts in its own console window. Is there a way for
it to run inside the python interface?

Thanks,
 
P

Peter Hansen

Ernesto said:
So i generated the .exe file "myFile.exe"

This is a Windows - text based application. Right now, when I run:

import subprocess
subprocess.call("myFile")

the application starts in its own console window. Is there a way for
it to run inside the python interface?

Google found the following (after I read the docs for subprocess and
learned about the "startupinfo" flag, and searched for "subprocess
startupinfo"). Does this help?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top