When using Mathematica script

#!/usr/local/bin/MathematicaScript -script

and running it with some arguments:

$./script.m a=6 z=3 d=423 c=43 x=1

I'm getting the following error:

Get::noopen: -- Message text not found -- (/SystemFiles/CharacterEncodings/ISO8859-1.m)

Get::noopen: -- Message text not found -- (/SystemFiles/CharacterEncodings/ISO8859-1.m)

Get::noopen: -- Message text not found -- (/SystemFiles/CharacterEncodings/ISO8859-1.m)

General::stop: -- Message text not found -- (Get::noopen)

Mathematica could not find its system-wide initialization file "sysinit.m". The following places were searched: . ~ ./Packages ./SystemFiles/KernelInit ./SystemFiles/GraphicsInit

{"./script.m", "a=6", "z=3", "d=423", "c=43", "x=1"}

With fewer number of command line arguments, this and any other script do not causes errors. How can one fix this issue? I'm running Linux 3.1.0-1-amd64 #1 SMP Tue Jan 10 05:01:58 UTC 2012 x86_64, together with Mathematica

  • 1
    $\begingroup$ It fails again. I can overtake this by calling math -script script.m {2,3,4,5,6} but this is ugly. The file "sysinit.m" about which Mathematica complains is present in a standard installation directory. $\endgroup$
    – mmal
    May 8, 2012 at 19:22
  • $\begingroup$ I am sorry, you are right, I can reproduce the problem. Removing one command line argument makes the problem disappear. $\endgroup$
    – Szabolcs
    May 8, 2012 at 19:23
  • 2
    $\begingroup$ Another strange thing is that when using more than 4 arguments, the first element in $CommandLine (not $ScriptCommandLine) will be shown as "" instead of the full path to MathKernel as it should be. I think this is a bug. $\endgroup$
    – Szabolcs
    May 8, 2012 at 19:35

4 Answers 4


Solution (tested on Linux)

Use this as first line of your script:

#!/usr/local/bin/MathematicaScript -runfirst "$TopDirectory=\"/usr/local/Wolfram/Mathematica/8.0\"" -script

If you installed Mathematica in a different directory, you have to adjust the path of $TopDirectory.

How did I debug this?

The first error message is quite clear: the system cannot open the file /SystemFiles/CharacterEncodings/ISO8859-1.m and obviously the system is correct, because this file does not exist in this directory.

You could now use strace to track down what happens (maybe you better redirect the output into a file)

strace -s 128 ./script.m 1 2 3 4 5

Looking into the output you probably stumble over the line


["", "-runfirst", "$TopDirectory=\"/usr/local/Wolfram/Mathematica/8.0\"", "-script", 
"./script.m", "--", "./script.m", "1", "2", "3", "4", "5"]

, [/* 54 vars */]) = 0

You see that basically you script-call is of course just a call to the MathKernel. If you execute this on the command-line, your script runs fine. This seems to suggest, that by providing 5 or more parameters, the setting of the $TopDirectory is somehow removed. Therefore, I tried to set it explicitly in the MathematicaScript-call which seems to work.

  • $\begingroup$ You can also use MathKernel or just math instead of MathematicaScript. I think the system extracts the installation path from the first item of $CommandLine. If this is missing, it can't find the installation directory and can't find its files. I came up with the same workaround you describe (+1!). Do you agree that this is a bug in MathematicaScript? $\endgroup$
    – Szabolcs
    May 9, 2012 at 8:41
  • $\begingroup$ @Szabolcs I agree with Your explanation about the paths. I've just run this (oryginal version - without any modifications) script on a different machine and I didn't get any errors. This suggests that this could be system dependent issue. $\endgroup$
    – mmal
    May 9, 2012 at 9:21
  • 1
    $\begingroup$ @Szabolcs, yes, this is a bug. Why should the number of arguments be restricted? And when it is, where is it documented? I assume no one tested this at Wolfram. $\endgroup$
    – halirutan
    May 9, 2012 at 11:41
  • $\begingroup$ @halirutan Just needed a confirmation from at least one person before adding the tag. $\endgroup$
    – Szabolcs
    May 9, 2012 at 11:57

I get two kinds of errors (different from yours) on Mma 8.0.4 Mac OSX, depending on the number of arguments:

(with the appropriate path for Mac OSX)

#!/Applications/Mathematica.app/Contents/MacOS/MathematicaScript -script

With 5 arguments, I get

error: 14: Bad address

and with 7 or more arguments, I get a segfault:

MathematicaScript(14538) malloc: * error for object 0x70000037: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug Segmentation fault: 11

A workaround is to change MathematicaScript to MathKernel, and use $CommandLine[[3;;]] instead of $ScriptCommandLine.

  • $\begingroup$ The workaround works for me too, on OS X (+1). $\endgroup$
    – Jens
    May 8, 2012 at 20:22

I can't reproduce this exactly on win7 mma 8.0.1. $ScriptCommandLine is empty, while $CommandLine returns

{"d:\\Math\\Mathematica\\8.0\\math.exe", "-noprompt", "-script", "./script.m", "a=6", "z=3", "d=423", "c=43", "x=1"}

As a workaround have you thought about using environment variables to pass information to your script? You can retrieve the value of an environment variable with a simple Environment["NAME_OF_VARIABLE"]

  • $\begingroup$ Environment seems not to be a good solution eg. when passing lists. By the way, the same happens when running: $./script.m {2,3,4,5,5} even when this script is empty. $\endgroup$
    – mmal
    May 8, 2012 at 19:09
  • 1
    $\begingroup$ I get the same thing both on Windows and Linux when using math.exe or math. $ScriptCommandLine is empty. However, if I use MathematicaScript (available only on Linux), then I get back the actual command line, starting with {"./script.m", ...}. $\endgroup$
    – Szabolcs
    May 8, 2012 at 19:18
  • $\begingroup$ @mmal Why can't list be passed using env. variables? $\endgroup$
    – Ajasja
    May 8, 2012 at 20:00
  • $\begingroup$ @Ajasja I agree, it can be done this way. But I don't think its the best/proper one. $\endgroup$
    – mmal
    May 8, 2012 at 20:12

I think this has been solved with the new command /usr/local/bin/wolframscript as explained here http://reference.wolfram.com/language/ref/program/wolframscript.html

I can confirm that it works on MacOS Sierra with Mathematica version 11.0.1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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