So when I copied the file into the question above, I copied from the Mathematica front-end, which interprets the file contents slightly differently. The contents of the file is actually
#!/usr/bin/env wolframscript
M[a_, T_] := (4 π^2 a^3)/(G T^2) /. {
G -> Quantity["GravitationalConstant"]
}
(* Assuming inclined around major axis, no change to major axis *)
m1 = M[a, T] /. {
T -> Quantity[15.7, "Years"],
a -> 0.183 * 60^-2 * π/180 * Quantity[7.9, "Kiloparsecs"]
} // UnitConvert;
Print["Assuming inclined around major axis: M = " <> ToString[m1, InputForm]]
m1S = UnitConvert[m1, "SolarMass"];
Print["\t = " <> ToString[m1S, InputForm]]
I had input π as a unicode symbol. Wolframscript didn't interpret this as the constant Pi, but when I open the file with the front-end it automatically converts any instance of π to \[Pi]
. The command line input was therefore unable to evaluate the expression as it doesn't know what the symbol π is, and there also seems to be some encoding issues in the output.
Strangely the unicode input seems to work if I invoke the file with wolframscript -script
, but not just with wolframscript
or with wolframscript -file
.
Sorry to waste anyone's time with an incorrect question.
Mea culpa!