5.16 run Mathematica m file as script

Thanks to Rolf Mertig reference for help on this.

Make a file foo.m such as

AppendTo[$Echo, "stdout"] 
SetOptions[ $Output, FormatType -> OutputForm ]; 
Integrate[Sin[x],x]
 

Now type, from DOS window

"C:\Program Files\Wolfram Research\Mathematica\10.1\math.exe" < foo.m
 

This will send input and output to screen. To send output to file do

"C:\Program Files\Wolfram Research\Mathematica\10.1\math.exe" < foo.m > log.txt
 

You can modify the PATH on windows to add the above to environment variable so not to have to type the long command each time