wolfram

NAME

wolfram starts the Wolfram Language kernel in a console interface.

SYNOPSIS

wolfram

wolfram -activate actkey

wolfram -script file

wolfram -run initcode

DESCRIPTION

wolfram runs the standalone Wolfram Language kernel in an operating system console or shell. A console-based kernel session normally reads input from , evaluates the expression and prints the result to . Input and output can be redirected using standard shell mechanisms. On some systems, wolfram and WolframKernel are the same program.

EXAMPLES

Interactive Operation

Run the Wolfram Language in an interactive REPL:

$ wolfram
Wolfram Language 12.0.0 for Microsoft Windows (64-bit)
Copyright 1988-2019 Wolfram Research, Inc.

In[1]:= 2+2

Out[1]= 4

In[2]:= 

Exit an interactive kernel with a custom exit code:

$ wolfram
Mathematica 12.0.0 Kernel for Mac OS X x86 (64-bit)
Copyright 1988-2019 Wolfram Research, Inc.

In[1]:= Exit[5]

Verify the exit code in a Unix-style shell:

$ echo $?
5

Code from a File

Evaluate Wolfram Language code from a file, with only explicitly printed expressions visible:

file.wls
sum=2+2
integral=Integrate[1,x]
Print["Results: ",{sum,integral}]
$ wolfram -script test.wl
Results: {4, x}

Evaluate Wolfram Language code from a file, printing each output:

$ wolfram < test.wl
Mathematica 12.0.0 Kernel for Mac OS X x86 (64-bit)
Copyright 1988-2018 Wolfram Research, Inc.

In[1]:= 
Out[1]= 4

In[2]:= 
Out[2]= x

In[3]:= Results: {4, x}

In[4]:=

Omit the banner and in/out prompts, and format the results in InputForm:

$ wolfram -noprompt < test.wl
4
x
"Results: "{4, x}

Initialization on the Command Line

Use the -run option to set a variable on startup:

$ wolfram -run 'AppendTo[$Path, "/favorite/path"]'
Wolfram Language 12.0.0 Engine for Linux x86 (64-bit)
Copyright 1988-2018 Wolfram Research, Inc.

In[1]:= Last[$Path]

Out[1]= /favorite/path

In[2]:=

By adding an explicit Exit[], the -run option can be used to evaluate an expression and exit:

$ wolfram -run 'Print[\"Hello World\"];Exit[]'
Wolfram Language 12.0.0 Engine for Linux (64-bit)
Copyright 1988-2018 Wolfram Research, Inc.
Hello World

Initialization from a File

Append custom_init.wl to the standard list of initialization files:

$ wolfram -initfile custom_init.wl

Avoid loading any initialization files:

$ wolfram -noinit

Use custom_init.wl as the only initialization file:

$ wolfram -noinit -initfile custom_init.wl

Activation

Perform automatic activation using an activation key:

$ wolfram -activate 1234-5678-ABCDEF

Automatic Web Activation received a password.

Creating password file entry in:
C:\Users\user\AppData\Roaming\Mathematica\Licensing\mathpass

Verify the license, maximum number of processes and available processes (tab-separated):

$ wolfram -licenseinfo
L1234-5678      8       8

Perform offline activation with an activation key and password:

$ wolfram -activate "1234-5678-ABCDEF 1234-567-890:8,8,16,16::20190130"
Creating password file entry in:
C:\Users\user\AppData\Roaming\Mathematica\Licensing\mathpass

Additional Examples

Check the version of the installation:

$ wolfram -version
12.0.0 for Mac OS X x86 (64-bit)

Check the value of $MachineID:

$ wolfram -machineid
6202-11889-09929

Print $MachineName and $MachineID, separated by tabs, as would go in a password file entry:

$ wolfram -machineinfo
lap27    6202-11889-09929

Allow the kernel to run using a different password file:

$ wolfram -pwfile "/path/to/mathpass"
Wolfram Language 12.0.0 Engine for Microsoft Windows (64-bit)
Copyright 1988-2019 Wolfram Research, Inc.

In[1]:=

Start a kernel and create a WSTP link:

$ wolfram -wstp -linkcreate
Link created on: mvg8t_shm

From another session, connect to the link, activate it and clear the input:

In[1]:=
Click for copyable input
Out[1]=

Send an evaluation to the linked kernel and compare the result to the current kernel:

In[2]:=
Click for copyable input
Out[2]=

Close the link:

In[3]:=
Click for copyable input

OPTIONS

Licensing Options

-activate actkey Perform or verify activation and exit.

-licenseinfo Display the value of $LicenseID as well as related information and exit.

-lmverbose Print information about interactions with MathLM.

-pwfile file Read the passwords from .

Startup Options

-initfile file Execute the commands in the initialization .

-noinit Do not read initialization files from standard locations.

-run cmd Run the command on startup.

Execution Mode Options

-script file Execute the commands from the in script mode.

-noprompt Do not print banner or In[] and Out[] prompts or ask for user input due to startup errors (useful for batch scripts).

-rawterm Assume a dumb terminal and disable cursor-key navigation.

-wstp Communicate only via WSTP.

Utility Options

-machineid Display the value of $MachineID and exit.

-machineinfo Display $MachineName and $MachineID, separated by tabs, then exit.

-version Display the product version and exit.

DETAILS

Wolfram Language Scripts

If the -script command-line option is given, the kernel evaluates commands from the in a batch, or script, mode and then terminates.

In script mode, the kernel prints no banner and no In[] or Out[] labels, and generates all output in InputForm, with the PageWidth option effectively set to Infinity.

In script mode, the standard input and output are not redirected, so that the input and output can be used in a pipe with other processes.

In script mode, the kernel ignores the first line of the file if it starts with the characters "#!".

Licensing Options

If a password file is specified using -pwfile, its passwords are tried first. If no valid passwords are found, password files in standard system locations are tried.

In -activate actkey, a key of the form $ActivationKey will perform online activation, verifying the key and downloading the latest password by contacting the Wolfram product activation server via the internet. A key of the form "$ActivationKey password" will perform offline activation without using internet access. In either case, zero is returned if activation is successful and a nonzero value otherwise.

The option -licenseinfo prints the value of $LicenseID, the maximum number of allowed Wolfram Language processes for that license and the number of available processes, separated by tabs. If no valid license is found, zeros are printed for all three fields and a nonzero exit status is returned.

Startup and Shutdown

The kernel will read the value of the environment variable and append its value to any command-line arguments.

Unless the Wolfram Language variable $IgnoreEOF is set to True, the kernel will exit when it receives an end-of-file character sequence. The kernel will always exit when given the command Quit.

When -noprompt is given, the variable $BatchOutput is set to True. In addition to omitting In[] and Out[] labels and the banner when it starts up, the Wolfram Language generates all output in InputForm, with the PageWidth option effectively set to Infinity.

The kernel will return a nonzero exit code if it cannot be started due to licensing or other problems. It will typically return a zero exit code upon termination, unless Exit[n] is used to return another value.

When -wstp is given, any general WSTP option understood by WSOpenArgcArgv may be given on the command line as well.

FILES

User initialization file locations:

  • $BaseDirectory/Kernel/init.m
    $UserBaseDirectory/Kernel/init.m
  • Password file locations:

  • $UserBaseDirectory/Licensing/mathpass
    $BaseDirectory/Licensing/mathpass
    $InstallationDirectory/Configuration/Licensing/mathpass
  • WOLFRAM LANGUAGE VARIABLES

    The following variables are set when WolframScript begins execution.

    $CommandLine A list of strings giving the complete command line used.

    $ScriptCommandLine A list of command-line arguments intended for the script being run. These come after options given with -option.

    ENVIRONMENT VARIABLES

    WOLFRAMINIT Additional arguments to append to every invocation of WolframKernel.

    MATHKERNELINIT Legacy variable that is read if WOLFRAMINIT is not defined.

    MATHEMATICA_BASE The path to use for the value of $BaseDirectory.

    MATHEMATICA_USERBASE The path to use for the value of $UserBaseDirectory.

  • System Administration Guide