0

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!

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Leonx
  • 413
  • 2
  • 9

1 Answers1

2

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.

Leonx
  • 413
  • 2
  • 9
  • 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. – J. M.'s missing motivation Nov 03 '17 at 04:08
  • 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.

    – Leonx Nov 03 '17 at 04:17