I want to run Mathematica "jobs" on a daily/weekly basis to do system maintenance and as part of daily processing operations. What is the best way to do this?

  • $\begingroup$ Although you reasked your question, I believe this is a duplicate as well. It just seems that you were unaware that one could run Mathematica from the command line without a FrontEnd. This is not something new to this whole "Wolfram Language" nonsense, but I believe has existed since version 1 (someone familiar with v1 can correct me if I'm wrong). If you were to actually focus your question and answer on the "doing system maintenance with Mathematica" part (with examples of scripts to do some common chores), then the question would be different and it can be reopened. $\endgroup$
    – rm -rf
    Dec 16, 2013 at 21:59
  • $\begingroup$ I don't think it's the same question. None of the answers to my original question explained how to do what I tried to ask about. If the question was trivial, and the answer was obvious, someone would have said so, and answered it. But they didn't. $\endgroup$ Dec 16, 2013 at 23:45
  • $\begingroup$ I was really interested in the mechanics of getting a Mathematica script to run in the background. I had never used MathKernel, so I didn't know how to do it. I didn't have any questions about how to do the system maintenance part. $\endgroup$ Dec 16, 2013 at 23:48
  • $\begingroup$ I do see that Verbeia provided an answer in October to the question I asked in June, but I didn't see her answer in the interim. So, I do see your point about a duplicate question. $\endgroup$ Dec 17, 2013 at 0:03
  • $\begingroup$ Hmmm... In your first question, it wasn't clear that you were referring to MathKernel, since you asked "How do I set up the notebook/file so it will execute when started without asking any questions?", hinting at a notebook approach (which the linked dupe addresses). As for this one, the link to Jens' website in bill s' answer to your first question addresses this. There he explains how to run scripts as a batch job, which was exactly what you were looking for. The only additional part is about adding it to the scheduler/cron, which you already knew about and is not related to Mathematica. $\endgroup$
    – rm -rf
    Dec 17, 2013 at 0:38

1 Answer 1


This turns out to be easy. In Windows 7:

  1. Add C:\Program Files\Wolfram Research\Mathematica\9.0\ to the path.
  2. Write procedures for what you want to do in The Wolfram Language, and save in a .m file.
  3. Add MathKernel.exe -script filename.m to the Windows Task Scheduler. Specify that the job runs in the directory containing the .m file.

That seems to be it. by using MathKernel.exe instead of Mathematica.exe you avoid problems related to Initialization Cells. By using the -script flag you tell MathKernel to end the job after executing the last line of code (evaluating the last function).

There has been some discussion on SE about the meaning/value/purpose of The Wolfram Language - it's a marketing ploy, etc. Here's what is especially interesting about my little question to me - it's an example of using The Wolfram Language without the Mathematica interface. People seem to confuse (IMHO) The Wolfram Language with Mathematica. So here it is: put code in .m files; run them with the MathKernel - you're using The Wolfram Language.

And, initially surprisingly to me, I don't need to invoke MathKernel directly to run the script. If, in a command line window, I moved to the folder holding the .m file, I can run the script just by typing filename.m on the command line. I'm calling it a script, but in fact it could be a very large program, so perhaps the term script obscures the fact that Wolfram Language programs don't require Mathematica.

I have recently found numerous references to MathKernel, scripts, and related topics in official Mathematica documentation that I didn't know about before. I'll list some of them:

  1. A list of "new in 8" scripting features.
  2. A Mathematica script tutorial.
  3. A MathKernel guide.

Perhaps in the future we will see more discussion about running Wolfram Language programs in the Mathematica MathKernel. If anyone has opinions about this, please comment.

  • 2
    $\begingroup$ Any bets that v10 will officially replace MatheKernel.exe with wolfram.exe? $\endgroup$ Dec 16, 2013 at 13:10
  • 1
    $\begingroup$ Can't really agree with this.."Wolfram Language programs don't require Mathematica" Should be "Wolfram Language programs don't require the Mathematica Front End" .. $\endgroup$
    – george2079
    Dec 16, 2013 at 21:07
  • 1
    $\begingroup$ It is true as george2079 says, that though this might be practically useful to someone the philosophical aspect is a bit deceiving. I wasn't around, but I bet you could send scripts to the kernel in v.1. It's so basic - and all other interpreted languages allow it - that it must have preceded the graphical interface. $\endgroup$
    – C. E.
    Dec 16, 2013 at 21:48
  • $\begingroup$ You could always directly access the kernel. IIRC, until recently thre was no -script option to let you nicely run in a batch mode. $\endgroup$
    – george2079
    Dec 16, 2013 at 22:20
  • $\begingroup$ If you started with Version 7 (like I did), you saw almost no discussion about the kernel, so this was something of a discovery for me. $\endgroup$ Dec 16, 2013 at 23:53

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