The following code runs fine if I run it interactively:

realpath[path_] := Import["!readlink "<>path, "Text"];
testsymlink = FileNameJoin[{$HomeDirectory, "testsymlink"}];
test = realpath[testsymlink];

In particular, the variable test gets the expected (non-Null) value.

The same code runs fine also if I put it in a standalone script and execute it with

<< "/path/to/script.m";

But if I put the same code, all by itself, in my Kernel/init.m file, it fails: the variable test gets the incorrect value Null. (The variable testsymlink, on the other hand, is still correctly set.)

Furthermore, if I then evaluate


interactively (in the newly started Mathematica session), I get the error shown in this post's title, twice:

Mathematica graphics

I can't figure out why I'm getting this error, but I'm having it may give someone else a clue as to why the snippet is failing in the first place (when run as part of executing Kernel/init.m.

PS: It appears that the offending snippet puts the session in a corrupted state, because when I attempted to upload the image shown above, I got this error:

Mathematica graphics

I had first restart Mathematica (after deleting the offending snippet from Kernel/init.m), before I could upload these images.

  • $\begingroup$ @kjo I'm passing through an akin pickle mathematica.stackexchange.com/questions/114041/…. Did you find any explanation ? $\endgroup$ – mitochondrial May 1 '16 at 4:29
  • $\begingroup$ @mitochondrial: no, I never did, unfortunately. $\endgroup$ – kjo May 1 '16 at 11:56
  • 1
    $\begingroup$ @mitochondrial: I just had a random (and, admittedly, very farfetched) thought: MATLAB files also end in *.m, and therefore in some systems, MATLAB is set as the default program for such files. Could there be a weird interaction between Mathematica and the desktop environment that leads Mathematica to conclude that a particular *.m file is not a "MathLink executable"? Grasping at straws here... I'd test this idea myself, but I no longer have access to the system where I got this error. $\endgroup$ – kjo May 1 '16 at 12:03

Your Answer

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

Browse other questions tagged or ask your own question.