34

Updated answer with Dockerfile After the release of wolfram engine I thought it is a good time to revisit this old answer and refine it a bit. First install docker on your machine. Follow docker setup from old answer. Dockerfile Create a file named Dockerfile with following content. FROM ubuntu LABEL version = "1.0" LABEL description = "Docker image ...


23

These two small programs -- math.exe is the same as wolfram.exe, and MathKernel.exe is the same as WolframKernel.exe -- are kernel loaders, which provide an interface to the same main kernel code residing in the dynamic library WolframEngine.dll (also known as mathdll.dll in versions prior to 10.1.0). Both accept the same command line options as documented ...


15

The command Run will do exactly that. For example, try Run["touch ~/Desktop/blankfile"] If you want to read the results back in, there are a few options, and the choice between them depends on exactly what you want to do. The RunThrough command lets you read the output of a command-line back as a Mathematica expression. For example, try RunThrough["bc", ...


15

It is not a good idea to try to run a notebook in command line mode. Whether or not it is possible, it is just not a good idea because notebooks can only be handled by the Front End, which is not a command line tool. If you go this route anyway, expect difficulties. The usual way is to extract the code you want to run into a plain text .m file and run ...


13

(Reposting my comment as an answer) The reason this is happening is that the Mathematica launcher script sets LD_LIBRARY_PATH so that libraries included in the layout will be found and used, and that setting is inherited by any external process started from the kernel. But, sometimes it may happen that the external executable is linked against a conflicting ...


13

The -script mode is an interface to the wolfram.exe's -script mode, which is a command-line version of Get. It essentially rewrites the command line, launches a kernel using the equivalent command, and then exits. It can only ever be used with a local kernel, and $ScriptInputString will always be None. In -file mode, wolframscript.exe launches a slave ...


12

I have automated a nightly backup process with Mathematica. I use a task scheduling program to run a longer version of the following .m file below with MathKernel. Functions like Complementmake it easy to copy new files from a working directory to a backup directory, and in general, Mathematica makes it easy to use sophisticated logic along with various ...


12

I'm not sure on which operating system you are and whether this makes a difference, but your 4 choice don't do the same. math -run file.m edit: When you change this command to math -run < file.m then it does the same as the next (wrong) alternative. Doesn't do anything with the content of file.m at all, because the -run option expects a command like ...


11

Here is an idiom used by many built-in functions to achieve this effect: doubleOurMoney::badarg = "`1` should be of the form money[number]"; doubleOurMoney[money[x_?NumericQ]] := money[2 x]; doubleOurMoney[args___] := ( Message[doubleOurMoney::badarg, args]; Null /; False ) Here I'm using _?NumericQ instead of _Real to make your function work on ...


11

It's somewhat of a meme that WL has a top-level function for everything, but it's kinda true: Classify["ProgrammingLanguage", Import["file.m", "Text"], "TopProbabilities" ] Edit To force Classify to pick between two options, you can use the ClassPriors option: Classify["ProgrammingLanguage", Import[&...


10

On Windows, MathKernel.exe launches the kernel running within a window. The standard output is redirected to that window. To avoid this redirection, we must run the kernel as a console application using Math.exe instead: "C:\Program Files\Wolfram Research\Mathematica\10.0\Math" ^ -noprompt ^ -script C:\Users\a\Desktop\test.m ^ "data goes here" ...


9

This turns out to be easy. In Windows 7: Add C:\Program Files\Wolfram Research\Mathematica\9.0\ to the path. Write procedures for what you want to do in The Wolfram Language, and save in a .m file. Add MathKernel.exe -script filename.m to the Windows Task Scheduler. Specify that the job runs in the directory containing the .m file. That seems to be it. by ...


9

Update a very simple solution to the OP has been given in this very duplicate post: all the outputs (in particular graphics) are then correctly inserted in the evaluated notebook without the need to insert/modify the original notebook with special commands. also, as asked in the comments, I added a way to monitor in real time the different kind of outputs ...


9

SeedRandom[1234567]; q = RandomReal[{-1, 1}, 6]; r0 = RandomReal[{-3, 3}, {6, 2}] q = q - Total[q]/6; phi = Sum[ q[[i]]/Sqrt[({x, y} - r0[[i]]).({x, y} - r0[[i]])], {i, 1, 6}]; f = -Grad[phi, {x, y}] Show[StreamPlot[Evaluate[f], {x, -4, 4}, {y, -4, 4}, StreamColorFunction -> "Rainbow", StreamColorFunctionScaling -> False], Graphics[Table[ ...


9

Download the latest WolframScript installer, which will work on macOS 10.14: The installer from wolfram.com/wolframscript should work – ilian Oct 25 at 16:10


8

Here is a minimal example on how to run a mathematica script on a raspberry pi. Create a simple script (I used my bash terminal to do it): echo "sum=1+1; Print[sum]" > test.wl Excecute the script: wolfram -script test.wl 2


8

Here's an ugly hack that works, based directly on this answer. This doesn't work on Windows. First create a LibraryLink function that can set an alternate signal handler: << CCompilerDriver` handlerlib = " #include <signal.h> #include <stdlib.h> #include <stdio.h> #include \"WolframLibrary.h\" // you may want to ...


8

To replicate the Ctrl+A Enter execution behaviour automatically you can run Solve.nb from a package file, say runSolve.m, containing the code below. While Wolfram Language Scripts are straightforward, this method has the advantage that output can be saved in the notebook as if it was being run manually. To run a notebook and monitor evaluation ...


8

I created public resources to simplify and automate PlatoManiac's answer for you and all of us: TLDR https://account.wolfram.com/access/wolfram-engine/free?operatingSystem=LINUX echo -n $'YOUR-WOLFRAM-ID-EMAIL@HERE.com\nYOUR-WOLFRAM-ID-PASSWORD-HERE\n' | sudo docker run --name my-wolfram-engine-container -i wolframlanguagefan/wolfram-engine-desktop-linux:...


8

I didn't check how formatting works in wolframscript but if you force it on your terms then it does not matter: TL;DR: use: $ wolframscript -cloud -code 'ToString @ TeXForm[ (d u)/(d t)]'


8

Here's a version of the script that works: #!/usr/bin/env wolframscript -print All -run \'Needs[\"ComputerArithmetic`\"]\' Ulp[1000.] This is a limitation of -print All that we probably should either document or find a fix for, though the latter is rather challenging. When executing a script normally or using -print, wolframscript can essentially tell ...


8

Certain functionality, most notably rasterizing graphics, is implemented by the front end. In your case it is the JPEG export that triggers this.


7

My advice is don't save your script as a .m file. Consider the following quote from the Mathematica documentation on scripts. The Mathematica script does not need to have the .m extension. An executable script is a full-featured program equivalent to any other program in a Unix operating system, so it can be used in other scripts, in pipes, subject to job ...


7

DirectoryName @ $InputFileName is the answer, right? And this will work whether you call it from a package or a notebook interface: parentPath = $InputFileName /. "" :> NotebookFileName[] parentDir = DirectoryName @ parentPath Check: path = FileNameJoin[{$TemporaryDirectory, "test.m"}]; Export[ path, "Print @ DirectoryName @ $InputFileName", "...


7

This is because the default format type is OutputForm when running on the command line. Add this to the beginning of your script to change it to StandardForm: SetOptions[First[$Output], FormatType -> StandardForm] References: $Output is the list of streams the output goes to, typically having a single entry. Streams and Low-Level Input and Output (we ...


7

You can use StringReplace to define a function to make the replacement and use FixedPointList to get the result of applying the function recursively to an input list: ClearAll[sR] sR = StringReplace[StartOfString ~~ Repeated["X", {8}] :> "XXXXX"]; str = StringJoin@ConstantArray["X", 14] "XXXXXXXXXXXXXX" FixedPointList[sR, str] {"XXXXXXXXXXXXXX", ...


7

Here is one way to do what you ask Through[{Mean@*List, Subtract}[1175., 247.]] (* {711., 928.}*) This works by using Composition (in its operator form) to apply List and then Mean to the inputs. You could also "Lift" (is that the correct functional programming term?) Subtract to operate on lists (as suggested by @LukasLang) Through[{Mean, Apply[...


7

While you can always abort a running evaluation manually with Command + . (or Ctrl + .), here are several ways to do this in Mathematica within a given script! It depends on your particular application and setting. The first two are more general than the rest. I'll run through (most of) the possibilities. Confirm and Enclose are useful for specific control. ...


7

DeleteCases requires a pattern, not a function, as second argument: f[x_] := DeleteCases[Gather[x], {_}] f[{1, 2, 2, 1, 4, 3, 5, 5, 2, 7, 8, 9, 0, 11}] (* {{1, 1}, {2, 2, 2}, {5, 5}} *)


6

From the documentation for Print: "Print sends its output to the channel $Output." Therefore you can just do this: $Output = OpenWrite["filename " <> DateList["Year", "Month", "Day"] <> ".txt"]; before you run the file. Something more structured would be like this: stream = OpenWrite["c:/users/gre/desktop/derp.txt"]; AppendTo[$Output, stream]...


Only top voted, non community-wiki answers of a minimum length are eligible