3
$\begingroup$

In Mathematica, when you call a function, messages may be generated and shown in a pink Messages window:

enter image description here

These messages are shown also for CDF files when you open them with Mathematica. I have noticed that when I open CDF files with CDF Player, then the messages a muted. The pink window is never shown.

I can understand that this is the desired behavior for CDF files for web-embedding. However, in the case of standalone CDF files, could it be possible to see these messages?

I am deploying with

CDFDeploy["filename.cdf", expr, "Method" -> "Standalone", "Target" -> "PlayerPro"]
$\endgroup$
  • $\begingroup$ I don't think it is possible. Even if you dynamically set CurrentValue[$FrontEndSession, PrintAction] = "PrintToConsole" for player. Probably the reason behind this is you could print "serious stuff" to message notebook and WRI doesn't want this for FreePlayer since NotebookWrite and friedns are suppressed and this could be a work-around for that. $\endgroup$ – Kuba Jun 15 '15 at 13:34
2
$\begingroup$

This is how I do this. It is not elegant, but it works. First I create a file where the error messages will be sent:

logFilename = CreateFile[];
log = OpenWrite[logFilename, FormatType -> OutputForm, PageWidth->Infinity];

Then we make sure that any generated messages are also sent to this file:

AppendTo[$Messages, log];

At this point, optionally, you can sent any additional messages to the log file:

Write[log, "Reading and parsing file\n"];

Before your function ends, remember to restore the $Messages value and close the stream:

Close[log];
$Messages = { $Messages[[1]]}

So this way, if something goes wrong, the user can check the log file to see if there are helpful messages in there.

In order to avoid having to open a log file, you can wrap the risky operation in with a Check and import back the log file into a message window:

Check[
   importAndParseFile[filename],

   CreateDialog[
       {TextCell["Error Parsing the file", "Section"],
        TextCell["While parsing the file, the following error was generated:", "Text"],
        TextCell[Import[logFilename, "TEXT"], "Message", "MSG"],
        DefaultButton[]}];
   Close[log]; $Messages = { $Messages[[1]]};
   Return[$Failed]]

Close[log]; $Messages = { $Messages[[1]]}
$\endgroup$
  • 1
    $\begingroup$ have you checked whether this works in the (free) CDF Player? I would guess it does not as that is not allowed to read/write to local files if I remember correctly... $\endgroup$ – Albert Retey Oct 1 '18 at 9:50
  • $\begingroup$ So far I have only used it with EnterpriseCDF. $\endgroup$ – Gustavo Delfino Oct 3 '18 at 20:39
  • $\begingroup$ with Enterprize CDF it should work... $\endgroup$ – Albert Retey Oct 3 '18 at 21:03

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.