Re: mathematica scripts (should work like perl and shell scripts)
- To: mathgroup at smc.vnet.net
- Subject: [mg17379] Re: mathematica scripts (should work like perl and shell scripts)
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Thu, 6 May 1999 02:44:04 -0400
- Organization: University of Western Australia
- References: <7gfr4a$6d7@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Daniel Reeves wrote: > 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. You should have a look into MathScript <http://www.mathscript.com/> > 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) I'm not sure that I understand exactly what you want. If test.mma contains the following commands: a=2+2 b=10!; a+b then, running Mathematica in batch mode, only output for the first and third commands goes to stdout: # math -batchinput -batchoutput < test.mma 4 3628804 You can get 3) by appending a \ to long line and 4) by appending ; Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://www.physics.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________