473,473 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Execute C code through Python

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

Oct 20 '05 #1
14 1959
Ernesto wrote:
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
Oct 20 '05 #2
import subprocess
subprocess.call("cmd")

Oct 21 '05 #3
Thanks. Can anyone provide an example of using *subprocess* to run
helloWorld.C through the python interpreter.

Oct 21 '05 #4
"Ernesto" wrote:
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>

Oct 21 '05 #5
On 2005-10-21, Ernesto <er*******@gmail.com> wrote:
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).
--
Grant Edwards grante Yow! Am I accompanied by
at a PARENT or GUARDIAN?
visi.com
Oct 21 '05 #6
On Oct 21, Grant Edwards wrote:
I'm guessing you're using Windows based on the question.


+1 QOTW.

--
_ _ ___
|V|icah |- lliott http://micah.elliott.name md*@micah.elliott.name
" " """
Oct 21 '05 #7
On 2005-10-21, Micah Elliott <md*@micah.elliott.name> wrote:
On Oct 21, Grant Edwards wrote:
I'm guessing you're using Windows based on the question.


+1 QOTW.


Yow! That's two in one day, what do I win?

--
Grant Edwards grante Yow! I'll take ROAST BEEF
at if you're out of LAMB!!
visi.com
Oct 21 '05 #8
Grant Edwards wrote:
On 2005-10-21, Micah Elliott <md*@micah.elliott.name> wrote:
On Oct 21, Grant Edwards wrote:
I'm guessing you're using Windows based on the question.


+1 QOTW.

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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 21 '05 #9
Grant Edwards wrote:
On 2005-10-21, Ernesto <er*******@gmail.com> wrote:
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


Unless you have a C interpreter installed. e.g.:

import os
os.system("eic helloWorld.C")

(Requires eic to be in your PATH.)

I doubt it's what the OP was looking for, though.

http://eic.sourceforge.net/

Oct 21 '05 #10

Fredrik Lundh wrote:
"Ernesto" wrote:
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>


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.

Oct 24 '05 #11
Ernesto wrote:
> 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 ?)


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>

Oct 24 '05 #12
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,

Oct 25 '05 #13
Ernesto wrote:
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/Coo.../Recipe/409002

-Peter
Oct 25 '05 #14

Peter Hansen wrote:

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/Coo.../Recipe/409002

-Peter


Thanks Peter! That's exactly what I need.

Oct 26 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sheila King | last post by:
I have searched for an answer to this question on the comp.lang.python archives at Google Groups, and also looked through the (sparse) MySQLdb documentation, and cannot confirm for a FACT what I...
2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
3
by: robert | last post by:
Hello, Anybody knows if it's possible to execute python code from an db. db=MySQLdb.connect(host="localhost",user="r",passwd="j",db="v") c=db.cursor() c.execute("""SELECT * FROM table...
19
by: citronelu | last post by:
Is it possible to execute a binary string stored within a python script as executable code ? The script is run under Windows, and the binary code (a full executable file) is stored in a variable...
2
by: stef | last post by:
hello, doing a simulation of another language (JAL), I translate the other language into Python code, then I execute this converted Python code. Now I need todo some checks and give visual...
5
by: johnny | last post by:
Anyone know how I can make Machine A python script execute a python script on Machine B ?
3
by: joe jacob | last post by:
I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added <Directory...
5
by: nimitsis | last post by:
Hello to everyone I wont to create 2 threads in Python ( thread01, thread02 ), which doing the follows : thread01, ask user to give a value to flag variable and write it to the shared memory of...
0
by: David | last post by:
- Are there any peculiarities with using curs.executemany(...) vs. multiple How many times are you calling execute vs a single executemany? The python call overhead will add up for thousands of...
7
by: ChaosKCW | last post by:
Hi I am trying to use pymssql, and have an issue where by the execute (not the fetch) is appearing to load all records into memory. if I execute con = pymssql.connect(...) cur =...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.