Message Boards Message Boards

Running .nb file with Windows task scheduler

Posted 3 years ago

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.

POSTED BY: Brian Parme
9 Replies

I actually have the same problem. Maybe windows will like better my putting the wolfram call in a bat file.

Posted 3 years ago

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.

https://community.wolfram.com/groups/-/m/t/1191487

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.

POSTED BY: Duncan Aitken
Posted 3 years ago

Still just getting the black cmd with no action. Tried creating a .wl file as well. When I open the .wls file and hit "run" it executes correctly.

enter image description here

POSTED BY: Brian Parme
Posted 3 years ago

By the way, if I navigate in cmd to my file directory and type the following, it executes no problem: wolframscript -run automatedFile.wls

POSTED BY: Brian Parme
Posted 3 years ago

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.

POSTED BY: Duncan Aitken
Posted 3 years ago

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?

POSTED BY: Brian Parme
Posted 3 years ago

The black command window is what I would expect from running wolframscript. <scriptname> 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 https://reference.wolfram.com/language/ref/program/wolframscript.html

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.

POSTED BY: Duncan Aitken
Posted 3 years ago

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 <scriptname> as an argument. https://reference.wolfram.com/language/workflow/RunWolframLanguageCodeFromTheCommandLine.html

POSTED BY: Duncan Aitken
Posted 3 years ago

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 <scriptname>.

Thank you for the help.

POSTED BY: Brian Parme
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract