WolframScript enables Wolfram Language code to be run from any terminal, whether or not a Wolfram kernel is available on the system.
With WolframScript, users can decide where and how to run their Wolfram Language code. Along with configurable kernel and cloud settings, WolframScript includes a collection of convenience functions for a wide variety of tasks, including running pure functions with command-line input, calling cloud APIs and exporting data to any format supported by the Wolfram Language. Now you can run code in the Wolfram Cloud with wolframscript -cloud or with #!/usr/bin/env wolframscript -cloud in Unix shell scripts.
Evaluate the Wolfram Language code 2+2 on a local Wolfram Engine:
$ wolframscript -code 2+2
4
Evaluate the Wolfram Language code 2+2 in the Wolfram Cloud:
$ wolframscript -cloud -code 2+2
4
Create a file to execute Wolfram Language code locally:
#!/usr/bin/env wolframscript
Print[2+2]
$ ./file.wls
4
Create a file to execute Wolfram Language code in the Wolfram Cloud:
#!/usr/bin/env wolframscript -cloud
Print[2+2]
$ ./file.wls
4
Create a file that uses a command-line argument:
#!/usr/bin/env wolframscript
Print[ToExpression[$ScriptCommandLine[[1]]]^2]
$ ./file.wls 5
25
Create a file giving a function whose arguments come from the command line:
#!/usr/bin/env wolframscript -function -signature City City
Print[GeoDistance[#1, #2]]&
$ ./file.wls "Champaign, IL" "Oxford, England"
Quantity[4010.4812837526256, Miles]
Run Wolfram Language Code from the Command Line with WolframScript
Create Wolfram Language Scripts
Deploy and Use a Cloud-Based API on the Command Line
Work with Files and Data on the Command Line Using Wolfram Cloud
WolframScript introduces a wide variety of command-line interactions to best fit your scripting needs.
Code can be passed to WolframScript directly on the command line with the -code argument, allowing the user to immediately display or redirect the output into a file.
Code can be run directly from Wolfram Language packages using the -file argument.
WolframScript can be used as a script interpreter, allowing for scripts to be written with the Unix #! syntax on systems where this is supported.
Pure functions can be defined and executed using data and arguments from the command-line environment, allowing for easy ad-hoc sequential operations.
Data streamed into WolframScript is captured into the $ScriptInputString symbol for easy processing of data either all at once or iteratively line by line.
WolframScript is now capable of executing code using the Wolfram Cloud. It can be configured to use either the public Wolfram Cloud or Private Cloud.
WolframScript is capable of parsing argument input and sending data directly to APIs hosted either in the Wolfram Cloud or Private Cloud using APIFunction.
WolframScript is capable of converting and exporting its data to any export format supported by the Wolfram Language using the -export argument.
WolframScript is now fully featured in Windows with support for the basic Windows command shell, MSYS or Cygwin.
WolframScript will automatically select the latest Wolfram kernel installed on the user's system (Windows, Mac).