Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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.

  1. Create a Mathematica script file which I called test.m here with the following content.

     Print[1+1]
    
  2. Create a runScript.py with the following content. Here I'm using the Python 2.7 function subprocess.check_output:

     import subprocess
    
     output = subprocess.check_output(['MathematicaScript', '-script', 'test.m'])
     print output
    
  3. Run the script with something like /usr/bin/python runScript.py.

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 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.

  1. Create a Mathematica script file which I called test.m here with the following content.

     Print[1+1]
    
  2. Create a runScript.py with the following content. Here I'm using the Python 2.7 function subprocess.check_output:

     import subprocess
    
     output = subprocess.check_output(['MathematicaScript', '-script', 'test.m'])
     print output
    
  3. Run the script with something like /usr/bin/python runScript.py.

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 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.

  1. Create a Mathematica script file which I called test.m here with the following content.

     Print[1+1]
    
  2. Create a runScript.py with the following content. Here I'm using the Python 2.7 function subprocess.check_output:

     import subprocess
    
     output = subprocess.check_output(['MathematicaScript', '-script', 'test.m'])
     print output
    
  3. Run the script with something like /usr/bin/python runScript.py.

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 SOStack Overflow to see how you can get the stdout of a command into a pythonPython 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 pythonPython script.

Here a working example. I don't have a RPIRaspberry Pi and therefore, the command is still good old MathematicaScript for me.

  1. Create a Mathematica script file which I called test.m here with the following content.

     Print[1+1]
    
  2. Create a runScript.py with the following content. Here I'm using the Python 2.7 function subprocess.check_output:

     import subprocess
    
     output = subprocess.check_output(['MathematicaScript', '-script', 'test.m'])
     print output
    
  3. Run the script with something like /usr/bin/python runScript.py.

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 SO 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 RPI and therefore, the command is still good old MathematicaScript for me.

  1. Create a Mathematica script file which I called test.m here with the following content

     Print[1+1]
    
  2. Create a runScript.py with the following content. Here I'm using the Python 2.7 function subprocess.check_output

     import subprocess
    
     output = subprocess.check_output(['MathematicaScript', '-script', 'test.m'])
     print output
    
  3. Run the script with something like /usr/bin/python runScript.py

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 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.

  1. Create a Mathematica script file which I called test.m here with the following content.

     Print[1+1]
    
  2. Create a runScript.py with the following content. Here I'm using the Python 2.7 function subprocess.check_output:

     import subprocess
    
     output = subprocess.check_output(['MathematicaScript', '-script', 'test.m'])
     print output
    
  3. Run the script with something like /usr/bin/python runScript.py.

added 572 characters in body
Source Link
halirutan
  • 113.4k
  • 7
  • 266
  • 479

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 SO 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 RPI and therefore, the command is still good old MathematicaScript for me.

  1. Create a Mathematica script file which I called test.m here with the following content

     Print[1+1]
    
  2. Create a runScript.py with the following content. Here I'm using the Python 2.7 function subprocess.check_output

     import subprocess
    
     output = subprocess.check_output(['MathematicaScript', '-script', 'test.m'])
     print output
    
  3. Run the script with something like /usr/bin/python runScript.py

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 SO 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.

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 SO 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 RPI and therefore, the command is still good old MathematicaScript for me.

  1. Create a Mathematica script file which I called test.m here with the following content

     Print[1+1]
    
  2. Create a runScript.py with the following content. Here I'm using the Python 2.7 function subprocess.check_output

     import subprocess
    
     output = subprocess.check_output(['MathematicaScript', '-script', 'test.m'])
     print output
    
  3. Run the script with something like /usr/bin/python runScript.py

Source Link
halirutan
  • 113.4k
  • 7
  • 266
  • 479
Loading