I'm currently working on a project that uses a C source file that has to interact with a python file (run the file and capture output) and im not exactly sure how to do it. currently the python file is run through terminal (linux) using:
python file arg1 arg2 arg3 arg4
and i am trying to embed python into the C code to just run the file first (no output capture) using the following code:
void python() {
FILE * file;
int argc;
char * argv[5];
argc=5;
argv[0]="pathtofile/file";
argv[1]="arg1";
argv[2]="arg2";
argv[3]="arg3";
argv[4]="arg4";
Py_SetProgramName(argv[0]);
Py_Initialize();
PySys_SetArgv(argc,argv);
file= fopen("pathtofile/file","r");
PyRun_SimpleFile(file,"pathtofile/file");
PyFinalize();
}
args1-2 are hard coded, and args3-4 are determined by the C code (just determines integer values), this is then passed to the python file where it then executes.
When running the above code i get a: TypeError: unsupported operand type(s) for + :NoneType and 'str'
Any advice from here on what could be my issue is greatly appreciated.
EDIT: I was using this as a guide as it seems to be similar to what im trying to acheive Run a python script with arguments