Message Boards Message Boards

Calling Mathematica from Python via DOS

The following Python file, named test.py is an example of how Mathematica can be called from Python via DOS:

import subprocess

import sys

wcode = 'StringReplace[ToString[Range[' + sys.argv[1] + ']],{ "{" -> "", "}" -> "", "," -> ""}]'

proc = subprocess.Popen(['wolframscript', '-code',wcode],stdout=subprocess.PIPE)

(out,err) = proc.communicate()

out = out.decode('ascii')

print(out)

in a cmd box, calling python test.py 5 gives 1 2 3 4 5

wolframscrpt's location had been added to the windows path

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract