I have access to a node of a Linux cluster, on which Mathematica is installed. However, I do not have access to a Linux GUI.
Typically I write and test Mathematica scripts on my Windows personal computer (with the typical GUI/front end). Then, I run the scripts on the Linux terminal because the terminal is significantly faster than my desktop computer (my scripts read and write a lot of data). I use the command:
math < test.txt
where test.txt
is a text file containing Mathematica code. I have been using this command successfully to run my scripts. I just always need to make sure that I do not try to print graphics to the screen, since I don't have a Linux GUI.
However, now I would like to write a script that prompts the user for input. For example, this code works fine on the Windows GUI:
Print["start"]; str = InputString[]; Print["string: " <> str]; Print["finish"];
But, it fails on the Linux terminal, generating this console output:
Mathematica 7.0 for Linux x86 (64-bit) Copyright 1988-2008 Wolfram Research, Inc.
In[1]:= start
In[2]:= ?
In[3]:= finish
In[4]:=
Is there any way I can prompt the user for input on a Linux terminal? The input does not necessarily need to be interactive. For example, I can imagine there being a way to pass an input string to math
by a command like:
math -input "This is my input string." < test.txt
but I am not sure what is the syntax to do this.
Addendum:
InputString[]
works on the terminal if I simply enter a terminal using the command:
math
and then type InputString[]
in the input prompt. However, this is not how I want to run my scripts, since this (I think) would require me to retype every command, line by line.
math -initfile test.txt
works, but it seems thatmath -script test.txt
does not. For me (Mathematica 7),math -script test.txt
just gives me a Mathematica input prompt, but does not execute the commands intest.txt
. I wonder what is the difference between-initfile
and-script
. $\endgroup$man math
says that-initfile
"Execute[s] the commands in the initialization file file during startup." I don't see-script
described inman math
. $\endgroup$-initfile
, and putQuit[]
at the bottom of my scripts. $\endgroup$