Search code examples
pythonccpython

how to run a C code with argc argv from python?


I need to run my c code from python, usually as adviced here I do this and works perfectly:

from subprocess import call
call(["./code", "args", "to", "code"])

I would like to run the code that in order to run needs argv, as a number, so for instance normally from shell I should call simply:

./code #certainNumber

I would like to pass a string at the call function, like:

D=1
str = "./code %d"(%D)
call([str, "args", "to", "code"])

obviously this does not work. I would like to chose from python the parameter that I need to insert in my c code.

thanks


Solution

  • As twalberg said this works perfectly:

    call(["./code", str(variableContainingNumber), "other", "args"])