Questions tagged [scripting]

For questions about Wolfram Language Scripts (formerly known as Mathematica Script), or running the kernel without direct user interaction.

Filter by
Sorted by
Tagged with
6
votes
3answers
1k views

Temporarily redirect the output of Print[ ] to a second file

I have started using Mathematica to automate file backup operations. The logistics I need make Mathematica a good choice. I am testing and developing the Notebook manually, and ...
10
votes
1answer
1k views

Analogue of NotebookDirectory[] for scripts (to get the directory path of my script.m)?

Is there a way to get the script directory from inside a Mathematica script? I want a function analogue to NotebookDirectory[] (which doesn't work for scripts). Is ...
5
votes
1answer
667 views

Can't run Bash scripts from within Mathematica 10.1

I am working on Debian 8 (Jessie) and Mathematica 10.1 (64-bit) Home Edition. I have created a script named curl_fetch.sh. It contains the line: ...
22
votes
3answers
2k views

Reading from STDIN, or: how to pipe data into Mathematica

Today I tried using Mathematica's plotting capabilities to display the output of a C++ program. This made me wonder whether it is possible to somehow tell a Mathematica script to read from STDIN and ...
35
votes
1answer
1k views

Why are all the lines commented when I create a Mathematica script?

When I created a Mathematica script, I found that all my lines were commented out (when opened with vi or gedit or any other ...
19
votes
1answer
1k views

Difference between “wolframscript -f” and “wolframscript -script”

In Mathematica 11, there is new wolframscript.exe According to help wolframscript.exe -h -f [ -file ] arg---------Run a ...
6
votes
2answers
383 views

UseFrontEnd is not working the same in version 10.4

I'm using batch files to run Mathematica notebooks (with saved output) but in version 10.4 the functionality has changed. Any ideas how to get it working? I use a batch file to run a .m script which ...
9
votes
2answers
9k views

Command line execution of Mathematica notebooks and conversion to .m

Sometimes one may want to execute a notebook via the command line (for example to run it remotely). As far as I know it's not possible to run notebooks directly, but ...
18
votes
2answers
14k views

Running Mathematica Notebook files in command mode

The question is, how can I run a .nb file in the kernel mode of Mathematica? I am not an expert in Mathematica, but one of our users who use this program says that ...
46
votes
1answer
3k views

math.exe vs wolfram.exe vs MathKernel.exe vs WolframKernel.exe (running scripts on Windows)

I generally consider Mma documentation very good. However, it is startlingly difficult to find useful information on running Mma batch scripts, especially on Windows. So ... just what would I enter ...
16
votes
1answer
2k views

Scheduling Mathematica scripts to run from a command line [duplicate]

I want to run Mathematica "jobs" on a daily/weekly basis to do system maintenance and as part of daily processing operations. What is the best way to do this?
20
votes
4answers
5k views

Mathematica script - passing command line arguments

When using Mathematica script #!/usr/local/bin/MathematicaScript -script Print[$ScriptCommandLine] and running it with some arguments: ...
9
votes
1answer
988 views

Launch a specific notebook automatically when Mathematica starts

I run Mathematica on an iMac running OS X 10.6.8. I have set the OS's "Launch Items" to include Mathematica so that the application opens when the computer boots. Now I want to go further and ...
17
votes
2answers
4k views

Printing a string in a Mathematica script

Here's a simple script saved in the file hello #!/usr/local/bin/MathematicaScript -script Print["Hello world"] I can then run ...
5
votes
1answer
521 views

Mathematica script - Using front end

I'm running Mathematica on OS X and I want to create an Automator action that converts spreadsheet files. I have written this script: ...
5
votes
2answers
511 views

Editing Wolfram Language Packages and Scripts

Background I am currently working on a large software development project written in the Wolfram Language and I would like to organize my code in Wolfram Language Packages and Scripts (.wl files. See ...
5
votes
1answer
349 views

How to execute an existing notebook with Wolfram Engine?

[My related question: mwe-for-compiling-functions-into-standalone-dll-and-calling-them-in-python - here I am exploring an alternative] I have downloaded, installed and activated the wolfram engine (...
5
votes
1answer
162 views

wolframscript command line output from ParallelDo kernels contains lots of gibberish

I run this code: ParallelDo[ Print["Hi"];, {i,Range[2]} ] And I get this: ...
3
votes
2answers
1k views

How to create an executable notebook in Mac OS X

All, I am looking for help to create a notebook to be executed via terminal in MAC OSX. The notebook uses the front end. This is what I have so far ...
1
vote
2answers
849 views

How to set the relative directory so that they work both in script and in notebook and portable?

Maybe the question is not clear, here I try to state it in more detail: I have a folder named project, for instance. In it I have two folders, one is named ...
7
votes
1answer
1k views

Installing WolframScript (12) on OSX (Catalina)

I did a clean install of Catalina (OSX 10.15) and Mathematica 12.0 installation was flawless. However I can't install WolframScript which I greatly need. During the installation, after typing my ...
5
votes
1answer
987 views

Interrupting package evaluation, handling error

I have some packages/scripts that I schedule the execution using Jobs in SQL server. For example, in some of then, I use to create reports and delivery by mail using Mathematica. All done using ...
18
votes
3answers
10k views

Proper way to run a Mathematica script (-script vs -run vs MathematicaScript vs <)?

Suppose I have a Mathematica script called test.m. There at least 4 ways to run this from the terminal: ...
17
votes
1answer
1k views

Evaluating a notebook programmatically with -ne

I am running Mathematica 10.2 on an Ubuntu workstation. I would like to be able to evaluate a notebook through the command line, and save its final state so that I can launch evaluation remotely ...
15
votes
2answers
1k views

Line by line processing with a WolframScript

I am having some difficulty understanding the correct syntax to enable a line by line processing of a file using a WolframScript. What I would like to do to mimic this simple python pipe in ...
11
votes
2answers
920 views

Evaluator option for Mathematica Scripts

I have mathematica with many additional kernels besides Local ( e.g., core1, core2, core3, core4 ... ) added through Kernel Configuration Options. I have been running multiple copies of a simulation (...
5
votes
1answer
125 views

Rendering graphics: UsingFrontEnd vs using a front end

I'm trying to understand how Graphics expressions are rendered. I create an invisible notebook, write a cell and evaluate it, then rasterize the notebook. ...
6
votes
0answers
274 views

Passing UTF-8 to wolframscript on the command line

I am trying to use Unicode input to wolframscript -c, like so: $ ./wolframscript -c '1/∞' â^(-1) The source of this behavior ...
4
votes
1answer
1k views

Is it possible to write Matlab-like scripts in Mathematica?

I have been using the Notebook in Mathematica for quite a while. While I like its interface, the problem is successive statements sometimes get read into different Inputs, and when I am rerunning the ...
2
votes
2answers
450 views

Parse command line arguments

I have been trying to parse command line arguments. There are a couple of types of options. 1. Mandatory 2. Optional 3. Alternative There are built-in/3rd ...
2
votes
1answer
598 views

Electric Field Plot

I want to show an electric field of several arrangements of point charges in xy-plane. I wrote a routine that plots an electric field of a charge: ...
6
votes
1answer
144 views

How to create a progress bar using Wolframscript?

I am using Wolfram script with a Mac OS. I have a long while loop dependent on the length of a list. i.e.: ...
1
vote
1answer
1k views

How to record all the output (including error messages) of a mathematica script in a file?

Is it possible to record all the output of a Mathematica script to a file? I am looking for the Mathematica equivalent of ...
9
votes
1answer
366 views

Saving a source file adds (* ::Package:: *) to the first line

I am running Mathematica 9 on a linux machine and I've encountered the following behaviour that I am trying to understand. When I'm editing multiple source (.m) files using mathematica saving adds a ...
6
votes
2answers
618 views

Why does Mathematica stop when run in the background in command line mode?

If I try to start a Mathematica script in the background from the command line, like this: math -script someFile.m & then the process gets automatically ...
6
votes
3answers
416 views

NotebookEvaluate with InsertResults -> True from the command line

Suppose I have a notebook template.nb like this: and I want to evaluate this notebook from the command line. So I wrote this Mathematica script: ...
5
votes
1answer
291 views

Wolfram Script Not Completing when ran as cron job

I have a fairly simple Wolfram script called from within a shell script that I would like to run at certain times. The shell script calls a python script to get some recordings to from GPIO and saves ...
4
votes
1answer
400 views

How to run multiple scripts in a row from command line using the same kernel?

Here is my shell script so far (I am using MacOSX): ...
3
votes
2answers
908 views

Passing arguments into a script in WolframScript

According to https://reference.wolfram.com/language/ref/program/wolframscript.html i can pass arguments to a file containing wolframscript. But i cannot find a way to actually use passed arguments. <...
3
votes
1answer
527 views

How to catch an interrupt (Control-C) in a script?

If a user hits Control-C when a script is running, they get an Interrupt> prompt, where they have to type exit or ...
3
votes
1answer
104 views

Stop a script. Just stop it

How can I stop a mathematica script? Abort[] does not stop the script, just jump over a number of lines and proceed with next lines of calculations. Also, killing ...
2
votes
2answers
303 views

Mathematica code in fortran [closed]

I have an integral in which the integrand is a combination of ratio of modified bessel function of second kind. I am able to find the solution of this integral with mathematica Nintegrate module with ...
1
vote
0answers
88 views

Write a mathematica script that returns the absolute path to its directory [duplicate]

Shell scripts occasionally hardcode paths to other files. This will break if these other files are relocated. Hence, you should refer to outside files always relative to the position of the shell ...
0
votes
1answer
1k views

StringJoin/FileNameJoin doesn't quite work in script

My mathematica script is as follows: ...
5
votes
2answers
310 views

How to prevent a standalone kernel from opening windows?

I am trying to make Mathematica do some plots for me as a part of a script. I have a .m file that basically does Import[] on ...
3
votes
1answer
175 views

Creating flags to use with wolframscript?

Is it possible to create flags to pass arguments into a script with wolframscript? I am trying to pass multiple variables that correlate to specific keys. For example, wolframscript -script ...
2
votes
2answers
552 views

How to find source of `FrontEndObject::notavail` warning?

I converted a large notebook (a ton of code!) into a free-standing WolframScript. When I run the script: several warnings of the form ...
2
votes
0answers
203 views

Random “silent” crash when running a math kernel in terminal for a long time [closed]

I sometimes use Mathematica to run very long calculations in the terminal (Debian). To do this I use the command: math -script (filename) Now after several hours ...
1
vote
1answer
101 views

Argument of complex number with a variable

I want to evaluate the following expression Arg[E^((0. + 6.66667*10^-12 I) omega)/(4 - E^((0. + 2.*10^-11 I) omega))] where the variable omega is real and ...
0
votes
0answers
520 views

Save Notebook as Wolfram Script?

It is possible to automatically save a notebook as a Package (see https://mathematica.stackexchange.com/a/1370/5340). The generated package file only contains the cells marked as Code. This has the ...