Re: mathematica scripts (should work like perl and shell scripts)
- To: mathgroup at smc.vnet.net
- Subject: [mg17397] Re: mathematica scripts (should work like perl and shell scripts)
- From: "P.J. Hinton" <paulh>
- Date: Thu, 6 May 1999 02:44:13 -0400
- Organization: "Wolfram Research, Inc."
- Sender: owner-wri-mathgroup at wolfram.com
On Mon, 3 May 1999 in article <7gfr4a$6d7 at smc.vnet.net>, Daniel Reeves <dreeves at eecs.umich.edu> writes: > I'd like to be able to create a file like the following: > > test.mma: > #!/bin/math -script > a = 2 + 2; > (* do some other stuff... *) > Print[a]; > (* do more stuff... *) > > then when I make test.mma executable and run it, it should print 4 to > stdout. Nothing else should go to stdout, just what's explicitly written. > This is the way that perl and shell scripts work and it would be very > convenient/nice/powerful for mathematica to work this way too. For > example, you could use mathematica directly as a cgi script. > > There are some issues though---things the kernel would have to do > differently when the -script option was specified: > 1) allow an input file to be specified as a command line arg > 2) ignore the first line of the input file (the #!/bin/math...) > (this is automatic in perl and shell scripts since # is comment) > 3) allow a single command to span multiple lines > (a way to do this would be ignore newlines except after semi-colons) > 4) not print anything to stdout unless told to > (a stricter version of -batchoutput) > > Let me know your thoughts, especially Wolfram developers. Too bad it's > too late for version 4! You can do something linke this in Mathematica 3 and earlier if you're working under a Unix shell. Here is a script input file, which I denote with a file named "test.m": [cut here] a = 2 + 2; Write["stdout", a]; [cut here] Your parent shell script (what you call "test.mma") would look something like this: [cut here] #!/bin/sh $topdir=/usr/local/mathematica # path to Mathematica installation. unsetenv DISPLAY # optional -- needed only if shell has this variable set math -batchinput -batchoutput < $@ [cut here] Multiline inputs in test.m are permissible provided that the syntax satisifes the criteria in Section A.2.10 of _The Mathematica Book_. FrontEndExecute[FrontEnd`HelpBrowserLookup["MainBook", "A.2.10"]] -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. http://www.wolfram.com/~paulh/ Disclaimer: Opinions expressed herein are those of the author alone.