简体   繁体   中英

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

正如twalberg所说的,这很完美:

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

You could always do the following

import os

# arguments is some list of arguments as strings
output = os.system(processname + " ".join(arguments))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM