subprocess, invoke C-program from within Python

大憨熊 提交于 2020-01-25 08:32:28

问题


I am trying to invoke a C-program, named “drule.c”, from within my Python-program “drulewrapper.py”. I am trying to use "subprocess" but cannot get it to work.

1) I compile “drule.c” on the Mac’s terminal and all works okay:

$ gcc -o drule drule c
$ ./drule D11
>P>Q>RQ

Fyi, the input -- “D11” -- are axioms in predicate logic; the output -- “>P>Q>RQ” -- is the theorem that is proven and which I then want to process further in my Python program.

2) I write a short Python program (drulewrapper.py) and compile it:

From subprocess import call
def CheckString():
     call(“./drule”, “D11”)

3) But when I run CheckString() I get errors:

    Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    CheckString()
  File "/Users/georgeszpiro/Dropbox/metamath/GApl/drulewrapper.py", line 3, in CheckString
    call("./drule","D11")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 267, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 609, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integerT

Can anybody help?

来源:https://stackoverflow.com/questions/49541728/subprocess-invoke-c-program-from-within-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!