7

Recently I found some old post on MathGroup where usage of undocumented command-line options -batchinput and -batchoutput is shown:

 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

But when trying to reproduce this behavior under Windows I get only first output printed in the console window. What am I doing wrong?

Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93
  • 2
    Perhaps the `-script` option (new in 8) is useful to you. It's not the same thing though, `Out=` lines won't be printed. – Szabolcs Jul 01 '11 at 12:10
  • @Szabolcs Please give an example of usage of this option (or link to it). `Out=` labels are not printed with the `-batchoutput` option. What is the difference between it and `-script`? – Alexey Popkov Jul 01 '11 at 13:10
  • 1
    @Aleksey, do you have version 8? With `-script` nothing at all is printed unless your program does some explicit output (e.g. uses `Print`). Please see under "more info": http://reference.wolfram.com/mathematica/ref/program/MathKernel.html Just run `math -script file.m` to run the commands from `file.m` as a "script". – Szabolcs Jul 01 '11 at 13:13
  • @Szabolcs I still do not have version 8 but I am interested in understanding its new functionality. So `Print` in script mode will print to console although "in a script mode the standard input and output are not redirected" as it is said on the documentation page? – Alexey Popkov Jul 01 '11 at 13:26
  • @Aleksey, in practice, it seems that the only thing that's printed is what you print explicitly from your program. Just like any simple scripting language. Now you can write little programs in Mma and run-them non-interactively with no front end and no distracting output. `$Post` and friends don't seem to be used in script mode so you can't hack it in a simple way to print all output in case that's what you need. I think I've read about free third party "front ends" that accomplish basically the same for earlier versions, but I don't really remember ... – Szabolcs Jul 01 '11 at 13:33

1 Answers1

8

I tested it and got both numbers as output. HOWEVER, if the last command is not followed by a carriage return, the output is exactly what you posted!

So, please check that you are ending your last line with a carriage return.

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190