Script returns a value in the stadout but not able to get value in return parameter

172 views Asked by At

I am using the callexec function to call a python script. The python script returns a value in the stadout but I am not able to get the value in the return parameter. Is there a way to pass the value to the results variable?

The is the CANape script that I am using:

double err;
char result[];

err = CallExecutable("C:\\Program Files (x86)\\Python38-32\\python.exe", "C:\\Users\\XXXX\\Desktop\\Read_Current.py 1", 1, result);

print("%s", result);

Thanks in advance

1

There are 1 answers

2
mzurawski On

The result buffer provided to CallExecutable will return the result of the exit code from the python program. The following python code if called will return 123 and that is what the value of result will be in your code above.

import sys sys.exit(123)

If you are looking to pass data back from the python script I've done this using the function DLL mechanism (there is some demo code included with CANape for this). It involves a little C++ wrapper to interface with python or other languages.