执行Python中的C程序? [英] Executing a C program in python?
问题描述
我有这个C程序,至少我认为是(文件:spa.c,spa.h)。有没有什么办法可以不经过额外的参数给Python的跨preTER执行Python的这个脚本(如果没有,会是什么争论呢?)
I have this C program, at least I think it is (files: spa.c, spa.h). Is there any way I can execute this script from Python WITHOUT passing extra arguments to the Python interpreter (if not, what would the arguments be?)
更新:感谢您的答复。该人士$ C $ C可以在 http://www.nrel.gov/midc/找到水疗/#寄存器
Update: Thanks for your replies. The source code can be found at http://www.nrel.gov/midc/spa/#register
(请不要被吓到的网址注册,如果您在填写表格,就可以立即下载文件(没有验证邮件等),我会尝试你的建议,并报告的结果。
(Please do not be scared by the 'register' in the url, if you fill in the form, you can immediately download the files (no validation mails, etc) I will try your suggestions and report back with the results.
更新2 :我编译使用gcc源$ C $ C,但现在它给了我尝试调用(当拒绝权限),运行Python作为根,即使(在Ubuntu 10 IM :10)
Update 2: I compiled the source code using gcc, but now it gives me a permission denied when trying to call(), even when running python as root (im on Ubuntu 10:10).
更新3 [错误8] Exec的格式错误
Update 3 [Errno 8] Exec format error
更新4 确定,我得到了它的工作。用printf程序输出值:
Update 4 Ok, I got it working. Program outputs values using printf:
>>> call(['/path'])
Julian Day: 2452930.312847
L: 2.401826e+01 degrees
B: -1.011219e-04 degrees
R: 0.996542 AU
H: 11.105902 degrees
Delta Psi: -3.998404e-03 degrees
Delta Epsilon: 1.666568e-03 degrees
Epsilon: 23.440465 degrees
Zenith: 50.111622 degrees
Azimuth: 194.340241 degrees
Incidence: 25.187000 degrees
Sunrise: 06:12:43 Local Time
Sunset: 17:20:19 Local Time
谢谢大家!
推荐答案
有一个 C脚本没有这样的事情。如果你意味着 C程序您需要编译 spa.c
和 spa.h
进入运行前的可执行文件。
There is no such thing as a C script. If you meant a C program you need to compile spa.c
and spa.h
into an executable before running it.
如果您使用 GCC 在Linux或Mac OS X:
If you use GCC in Linux or Mac OS X:
$ gcc -Wall spa.c -o spa
会得到你的可执行文件名为温泉
。
在这之后,你可以运行从你的Python脚本与水疗中心
程序:
After that, you can run spa
program from your Python script with:
from subprocess import call
call(["./spa", "args", "to", "spa"])
这篇关于执行Python中的C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!