This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Mathematica Sessions

Command-Line Options and Environment Variables

-pwfileMathematica password file
-pwpathpath to search for a Mathematica password file
-runMathematica input to run (kernel only)
-initfileMathematica initialization file
-initpathpath to search for initialization files
-noinitdo not run initialization files
-mathlinkcommunicate only via MathLink

Typical command-line options for Mathematica executables.

If the Mathematica front end is called with a notebook file as a command-line argument, then this notebook will be made the initial selected notebook. Otherwise, a new notebook will be created for this purpose.
Mathematica kernels and front ends can also take additional command-line options specific to particular window environments.
MATHINITcommand-line environment for the Mathematica front end
MATHKERNELINITcommand-line environment for the Mathematica kernel
MATHEMATICA_BASEsetting for $BaseDirectory
MATHEMATICA_USERBASEsetting for $UserBaseDirectory

Environment variables.

Mathematica will read the values of operating system environment variables, and will use these values in addition to any command-line options explicitly given.


On startup, the Mathematica kernel does the following:
  • Performs license management operations.
  • Runs Mathematica commands specified in any options passed to the kernel executable.
  • Runs the Mathematica commands in the systemwide initialization file .
  • Runs the Mathematica commands in the user-specific initialization file .
  • Loads and files in Autoload directories.
  • Begins running the main loop.

The Main Loop

All Mathematica sessions repeatedly execute the following main loop:
  • Read in input.
  • Apply $PreRead function, if defined, to the input string.
  • Print syntax warnings if necessary.
  • Apply $Pre function, if defined, to the input expression.
  • Assign In[n].
  • Evaluate expression.
  • Apply $Post function, if defined.
  • Assign Out[n], stripping off any formatting wrappers.
  • Print expression, if it is not Null.
  • Clear any pending aborts.
Note that if you call Mathematica via MathLink from within an external program, then you must effectively create your own main loop, which will usually differ from the one described above.


During a Mathematica session messages can be generated either by explicit calls to Message, or in the course of executing other built-in functions.
f::name::langa message in a specific language
f::namea message in a default language
General::namea general message with a given name

Message names.

If no language is specified for a particular message, text for the message is sought in each of the languages specified by $Language. If is not defined, a definition for General::name is sought. If still no message is found, any value defined for $NewMessage is applied to and .
Quiet[expr] evaluates expr while preventing messages from being printed during the evaluation. Off[message] prevents a specified message from ever being printed. Check allows you to determine whether particular messages were generated during the evaluation of an expression. $MessageList and MessageList[n] record all the messages that were generated during the evaluation of a particular line in a Mathematica session.
Messages are specified as strings to be used as the first argument of StringForm. $MessagePrePrint is applied to each expression to be spliced into the string.


Exit[] or Quit[]terminate Mathematica
$Epilogsymbol to evaluate before Mathematica exits
$IgnoreEOFwhether to exit an interactive Mathematica session when an end-of-file character is received
end.mfile to read when Mathematica terminates

Mathematica termination.

There are several ways to end a Mathematica session. If you are using Mathematica interactively, typing Exit or Quit on an input line will always terminate Mathematica.
If you are taking input for Mathematica from a file, Mathematica will exit when it reaches the end of the file. If you are using Mathematica interactively, it will still exit if it receives an end-of-file character (typically Ctrl+d). You can stop Mathematica from doing this by setting $IgnoreEOF=True.

Network License Management

single-machine licensea process must always run on a specific machine
network licensea process can run on any machine on a network

Single-machine and network licenses.

Copies of Mathematica can be set up with either single-machine or network licenses. A network license is indicated by a line in the file starting with !name, where name is the name of the server machine for the network license.
Network licenses are controlled by the Mathematica license management program , which is run on the server machine. This program must be running whenever a Mathematica with a network license is being used. Typically you will want to set up your system so that is started whenever the system boots.
• Type directly on the command line
• Add as a Windows service

Ways to start the network license manager under Microsoft Windows.

• Type directly on the Unix command line
• Add a line to start in your central system startup script

Ways to start the network license manager on Macintosh and Unix systems.

When is not started directly from a command line, it normally sets itself up as a background process, and continues running until it is explicitly terminated. Note that if one process is running, any other processes you try to start will automatically exit immediately.
-logfile filewrite a log of license server actions to file
-loglevel nhow verbose to make log entries (1 to 4)
-logformat stringuse a log format specified by string
-language namelanguage to use for messages (default )
-pwfile fileuse the specified file (default )
-timeout nsuspend authorization on stopped Mathematica jobs after n hours
-restrict fileuse the specified restriction file
-mathidprint the MathID for the license server, then exit
-foregroundrun in the foreground, logging to
-installinstall as a Windows service (Microsoft Windows only)
-uninstalluninstall as a Windows service (Microsoft Windows only)

Some command-line options for .

For more detailed information on , see "Mathematica System Administration".
monitorlma program to monitor network license activity
monitorlm namemonitor activity for license server name

Monitoring network license activity.

If is run in an environment where a web browser can be started, it will automatically generate HTML output in the browser. Otherwise it will generate plain text.
-file filewrite output to a file
-format specuse the specified format (, , or )
-template fileuse the specified file as a template for the output

Some command-line options for .