1

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

Jonw3
  • 23
  • 4

1 Answers1

0

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.

mzurawski
  • 21
  • 2
  • Hi User. Could you further explain how you send back information to python with the DLL?. Thanks – Jonw3 Jan 18 '21 at 12:03
  • There is some source code with the Function DLL demo in CANape. Start with that and then follow https://stackoverflow.com/questions/3286448/calling-a-python-method-from-c-c-and-extracting-its-return-value. There is also a C-RT DLL demo in CANape, but I haven't used that yet with Python. – mzurawski Jan 19 '21 at 20:41