2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Szabolcs Dec 8 '16 at 17:43
  • $\begingroup$ In case you suspect front end trouble, to test if a front end is available, check that Head@UsingFrontEnd[$FrontEnd] === FrontEndObject $\endgroup$ – Szabolcs Dec 8 '16 at 17:46
  • 1
    $\begingroup$ 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... $\endgroup$ – ihojnicki Dec 8 '16 at 19:55
  • $\begingroup$ 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. $\endgroup$ – Karsten W. Dec 9 '16 at 10:25
3
$\begingroup$

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[];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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