4
$\begingroup$

Edit: I made a stupid mistake, see answer below

Whenever I execute wolframscript code from the command line, my Print[] output doesn't get evaluated, however if I run the exact same file with the Mathematica front end it works fine. I can't work out why this might be happening, it doesn't seem to be a situation where Evalute[] helps.

Example:

M[a_, T_] := (4 \[Pi]^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 * \[Pi]/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]]

Gives me to following output on the command line, which isn't what I expect:

command line output

But when I run it in Mathematica it gives me exactly what I expect

enter image description here

wolframscript --version gives me WolframScript 1.2.0 for MacOSX-x86-64. Mathematica 11.3 is installed.

Thanks for any advice.

$\endgroup$
5
  • $\begingroup$ I would guess that the front end is using a Wolfram server to interpret the Quantity entities and that the kernel, which is what the script talks to, can't do that. $\endgroup$
    – m_goldberg
    Commented May 27, 2018 at 15:51
  • $\begingroup$ I am having trouble reproducing this, can you share any more details about which version of Mathematica you are using as well as wolframscript --version? I don't think a front end is needed in this case. $\endgroup$
    – chuy
    Commented May 29, 2018 at 15:00
  • $\begingroup$ @chuy Sure: WolframScript 1.2.0 for MacOSX-x86-64. The Mathematica front end is reports version 11.3 $\endgroup$
    – Jasper
    Commented May 30, 2018 at 15:44
  • $\begingroup$ What do you see when you try wolframscript -code 'Quantity[10,"pounds"]'? $\endgroup$
    – chuy
    Commented May 30, 2018 at 17:00
  • $\begingroup$ @chuy I get Interpreting unit .... Quantity[10, Pounds] $\endgroup$
    – Jasper
    Commented May 31, 2018 at 1:47

1 Answer 1

3
$\begingroup$

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. (This seems to be discussed here.)

Sorry to waste anyone's time with an incorrect question.

Mea culpa!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.