The os.system
command will not help you, because it does not return/provide the output of the command executed. What you want is to have a look at this answer on Stack Overflowthis answer on Stack Overflow to see how you can get the stdout of a command into a Python variable.
In your Mathematica script you simply Print
the result and with the given method in the other answer you will fetch this result to your Python script.
Here a working example. I don't have a Raspberry Pi and therefore, the command is still good old MathematicaScript
for me.
Create a Mathematica script file which I called
test.m
here with the following content.Print[1+1]
Create a
runScript.py
with the following content. Here I'm using the Python 2.7 functionsubprocess.check_output
:import subprocess output = subprocess.check_output(['MathematicaScript', '-script', 'test.m']) print output
Run the script with something like
/usr/bin/python runScript.py
.