# Tag Info

8

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. ...

7

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 ...

6

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 ...

5

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

5

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 ...

4

On Windows there are two kernel executables: MathKernel.exe and math.exe. MathKernel.exe has its own input window, which may show up separately when you start the process from a command window. If you run it in MathLink mode, it may still show as a taskbar button. math.exe runs in a standard Windows command window. If you start it from within an existing ...

4

According to the documentation, To suppress the loading of kernel initialization files, use the kernel command-line option -noinit. To specify another file to be used for kernel initialization in addition to init.m, use the kernel command-line option -initfile file, where file is the additional initialization file.

4

3

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, ... 3 Clusters can be significantly different from each other, so I strongly recommend you talk to someone who uses the same system and ask them for help with the details. However, there is one thing that is clearly incorrect in your job script: To run a script with Mathematica, you need to start the kernel (command line program), not the front end (graphical ... 2 For this kind of "logging" in SubKernels for example I use the following code: oldoutput =$Output; (* store $Output *) oldmessages =$Messages; (* same for $Messages *) CheckAbort[ logstream = OpenWrite["yourlog.log"];$Output = {logstream}; (* redirect $Output *) AppendTo[$Messages, logstream]; (* add the logfile as an additional destination for ...

2

You can solve the issue by wrapping your code with UsingFrontEnd[].

2

This is because your shell doesn't allow background processes to print to the console. For instance tcsh has this behavior by default: % echo "a"& [1] 26502 % [1] + Suspended (tty output) echo a % fg echo a a In pretty much all shells you should be able to disable this behavior with stty -tostop % stty -tostop % echo "a" & [1] 26539 a % ...

2

Mathematica for unknown reasons is waiting for input. Possible solution echo | math -script someFile.m &

2

This is not an issue with Mathematica itself. It's related to how you closed the session on the remote machine. If you use screen, you should detach from the current screen session before exiting, otherwise you'll close the current shell together with its child processes, including Mathematica. Alternatively, just use nohup, and do not bother with screen: ...

1

I don't recommend modifying Print to redirect the output when it is not necessary. Instead, you can build up a custom solution that suits your needs. I use a variant of the following for logging in my projects and you should be able to tweak them to your application. Clear[logFile, writeLog, showLog]; logFile := "project-" <> DateString[##, {"Year", ...

1

I often had to run slow code on a cluster in a command line. Of course, you always want to write your code and debug in the FrontEnd if at all possible so it is important to support both methods of opening the file. My solution was to have my code as a .m file and then dump the output to a binary mathematica file to read later (in the frontend if I was ...

1

As far as I know it's not possible to run notebooks directly It is possible, and there is no need to convert .nb to .m if you want to execute it without FrontEnd. Notebooks are nothing but Mathematica expressions, so it is not difficult to sketch a script that would evaluate all Input cells in that expression, add new cells with the newly calculated ...

1

This is already built-in; Print directs all output to the $Output channel where a channel is just a list of open streams. So, to redirect it, simply oldout =$Output; strm = OpenAppend["filename "<>DateString[]<>".txt"]; $Output = {strm}; and to switch it back$Output = oldout; Close[strm]; Assuming you just want an ...

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