0

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?

4
  • Firstly, does any other program work? I'd suggest e.g. ls or something harmless. If yes, you can reduce your question. Then, please read about a minimal reproducible example. Your code is neither C nor V, which makes it hard to reason about. Commented Mar 28, 2018 at 18:37
  • 2
    You should send one arg to call(), and it should be a list: call(['./drule', 'D11']) Commented Mar 28, 2018 at 18:42
  • thanks jordanm. I did what you suggested and now I do not get an error message but just a "0" as output Commented Mar 28, 2018 at 18:49
  • 1
    0 means it worked but you need to use check_output to get the result since call just returns the exit code Commented Mar 28, 2018 at 19:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.