0
$\begingroup$

I have a simple test.m file:

(*--- file test.m -------*)
Print["Testing"]
Integrate[Sin[x],x]
(*---- end of file ------*)

And I executed it in command line (Windows 7 + Mathematica v11.0) like this:

C:\Program Files\Wolfram Research\Mathematica\11.0>math < c:\temp\test.m > c:\temp\output.txt

No output "Out[n]" was found in the output.txt:

Output.txt

The .m file is executed fine via the Mathematica Frontend.

Any advise please? Thanks!

$\endgroup$

1 Answer 1

2
$\begingroup$

My bad, it turns out that all lines are commented as I used the FrontEnd to create the script in input cells and saved it as a package or script file. My actual working file was a notebook hence the package was converted that way (via File->Save as).

I only noticed that when the script was opened via a text editor like notepad, obviously this has been discussed in this question.

IMO, Mathematica shall be able to convert a .nb to .m without commenting, or provide an option in the save as dialog to bypass commenting.

$\endgroup$
2
  • $\begingroup$ Cells that are not initialization cells in a notebook are converted to comments when the notebook is saved as a package/script. So, select all the cells you want to be executable and then press Ctrl+8 to turn them into initialization cells. $\endgroup$ Commented Nov 3, 2017 at 4:08
  • $\begingroup$ Yep, only realized it just now. In reality, most cells in a notebook are executable except those are commented, then one would think Mathematica would preserve such cells when converting to a package or script. $\endgroup$
    – Leonx
    Commented Nov 3, 2017 at 4:17

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.