I have a .nb file (with one cell) that I would like to evaluate every day. The easiest way seems to use Windows task scheduler. I set the .nb file up, so the cell is an initializer (starts running as soon as the file is opened). However, I can’t get the file to open with Windows task scheduler. As the action, I have the following parameters:
Program: Currently pointing to mathematica.exe, but I have several options:
mathematica.exe,
math.exe,
MathKernel.exe,
wolfram.exe,
WolframKernel.exe,
wolframscript.exe
Arguments (optional): I was using “-run file.nb” but tried many alternatives based on what I found around the web
Start in (optional): I have the directory where the file.nb is located for this.
I also read about saving the .nb file as another type of file. I tried saving it as a .m but couldn’t get it to work either with the task scheduler. Save options:
Wolfram Notebook (.nb),
Wolfram Language Package (.wl),
Wolfram Mathematica Package (.m),
Wolfram Language Script (.wls),
along with several others
For reference, I am using Wolfram Mathematica 12 student edition and Windows 10 home edition. Any help would be greatly appreciated.
There’s a workflow for running a Wolfram Language script from the command line. I’d try converting the .nb file to a .wls file and calling wolframscript.exe from within Windows task scheduler and supply -file as an argument.
Thanks. I tried using wolframscript.exe as the program and “-file.wls” as the argument, but it just brings up a black cmd looking window and does nothing further. I’m not sure what you mean by .
The black command window is what I would expect from running wolframscript. is a placeholder for the name of the file containing your .wsl code. If you use the argument “-file filename.wsl”, it will execute the code in “filename.wsl”.
Here’s the documentation for wolframscript itself which may provide a better explanation
Note that if you want to display output on the command window you either have to call the Print[] function in your code or use the “-print” or “-print all” options on the command line. “-print” will display the output of the last line executed; “-print all” will display output from all lines unless output from that line is suppressed using a semi-colon.
I tried that and still just get the black command window with a blinking cursor (and no completion of the code even after sitting for a while - I would see a download appear if it had completed). Do I need to do anything to the .nb file before saving it as a .wls?
I think you’ll need to create a new .wls file from scratch, e.g., by using File > New > Package/Script > WolframScript Script (.wls) and copy and paste the code from the .nb file into the new .wls file and then save it.
In my experience, if you just use File > Save As… to save a .nb file with a .wls extension, all the code from the .nb file will be commented-out in the .wls file and the commented-out code will have no effect when you execute the script.
I’m not sure I can be any more help, but I did find a Wolfram blog post that describes how Windows Task Scheduler was used to run a script every 5 minutes. The blog post links to the code. Perhaps you could use it as a guide.
The code provided uses a .bat file to create a scheduled task that calls a .vbs script, that calls a second .bat file, that passes a .wl file as an argument to wolframscript.