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

5

I stumbled on this bug today, on a linux box. Same symptoms, redirection of the stdout from an executable script, thescript, that begins with #!/usr/bin/env MathematicaScript -script (* math stuff *) when invoked as $./thescript arg1 > somefile or$ ./thescript arg1 | head resulted in an empty somefile and nothing from head. But without piping ...

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

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

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

4

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

It turns out if you run an exteral process it gets stdin.. img=Import["!python readstdin.py","tiff"]; Print[Dimensions[ImageData[img]]]; where my python script is just this: import sys print sys.stdin.read() seems to work: math -script script.m < file.tiff (* {900,1200,3} *) Edit .. even better..: img=Import["!cat -","tiff"];

3

I can't help with the Windows part it, but I would imagine this is a two step operation. First, invoke Mathematica -- which you can do form the command line (or cron, presumably), as shown by the instructions here, and have Mathematica open the desired notebook. Once started, you can ensure that the commands will be run by using initialization cells, which ...

3

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

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

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 hope someone will post here an answer based on InitializationCells because I wasn't able to make them work for me. This is quick walkaround: DynamicModule[{}, Framed["dir created"] , Initialization :> ( CreateDirectory[FileNameJoin[{"C:", "Users", "Kuba", "Desktop", "dir1"}]]; CreateDirectory[FileNameJoin[{"C:", "Users", "Kuba", ...

1

I found a working solution. I played around writing the FrameTicks function as a pure function. The problem seems to be that the argument passed to the fticks function are DateList generated lists and not of type Real when using the script engine. Don't ask me why but they are of type Real when using the graphical frontend (does somebody know why?). This ...

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