2

When I run the following script from command line,

Needs["JLink`"];
ConnectToFrontEnd[];
resultChart = UseFrontEnd[JuliaSetPlot[0.365 - 0.37 I]];
UseFrontEnd[Export["test.png", resultChart]];
CloseFrontEnd[];

the graphic file gets written out fine. In fact, the calls to ConnectToFrontEnd, UseFrontEnd, CloseFrontEnd are not even necessary.

However, if I call this script from Windows task scheduler, the function ConnectToFrontEnd returns True, but then an error is returned:

Rasterize::type : Notebook[ -- omitted --] cannot be rasterized.

I am aware of these two, similar questions, however I do not know what to do now here.

Karsten W.
  • 1,383
  • 8
  • 21
  • There is the builtin UsingFrontEnd, so you don't need UseFrontEnd from J/Link. But neither JuliaSetPlot, nor Export need it. (Export should make use of it internally). I don't know why it doesn't work for you, but what happens if you drop the unneeded parts? – Szabolcs Dec 08 '16 at 17:43
  • In case you suspect front end trouble, to test if a front end is available, check that Head@UsingFrontEnd[$FrontEnd] === FrontEndObject – Szabolcs Dec 08 '16 at 17:46
  • 1
    I haven't personally tried this before, so YMMV... I would switch to UsingFrontEnd and then ensure that when the task scheduler runs your script it has access to a desktop session. Kinda like on X, the Windows FE requires this to do just about everything... – ihojnicki Dec 08 '16 at 19:55
  • Thank you for your comments. Head@UsingFrontEnd[$FrontEnd]===FrontEndObject returns True. Switching to UsingFrontEnd did not help. Running the task with the option checked "only run if user is logged on" (which I interpret as making sure that there is access to a desktop session) does work! I am not an admin, so I am not sure if that is an option in the long run. – Karsten W. Dec 09 '16 at 10:25

1 Answers1

3

I did some experiments with MMA on Windows and it seems like silent FE execution (when a user is not logged on) is not working for functions that need to execute FE (even in the background). I suspect there might be a way to resolve it if proper permissions are set, but I don't know if it's worth it, besides this might be not available for all users.

There is an easier way though. If there is an Internet connectivity, I can suggest using the Wolfram cloud to evaluate and render the object. This script works perfectly in a task scheduler whether a user is logged on or not.

resultChart = JuliaSetPlot[0.365 - 0.37 I];
CloudConnect["...","..."]
co=CloudObject["temp"];
CloudEvaluate@Export[co, resultChart,"PNG"]
Export["testcloud.png",CloudImport[co],"PNG"];
DeleteFile[co];
CloudDisconnect[];
Stitch
  • 4,205
  • 1
  • 12
  • 28