0

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

Community
  • 1
  • 1
user3585292
  • 57
  • 1
  • 7

2 Answers2

0

As twalberg said this works perfectly:

call(["./code", str(variableContainingNumber), "other", "args"])
user3585292
  • 57
  • 1
  • 7
-1

You could always do the following

import os

# arguments is some list of arguments as strings
output = os.system(processname + " ".join(arguments))
AndrewGrant
  • 786
  • 7
  • 17