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?

jordanm
  • 33,009
  • 7
  • 61
  • 76
george s
  • 9
  • 1
  • 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 [mcve]. Your code is neither C nor V, which makes it hard to reason about. – Ulrich Eckhardt Mar 28 '18 at 18:37
  • 2
    You should send one arg to `call()`, and it should be a list: `call(['./drule', 'D11'])` – jordanm Mar 28 '18 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 – george s Mar 28 '18 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 – eagle Mar 28 '18 at 19:03

0 Answers0