Here is a sample session illustrating the problem. The file "test.m" just contains "a=b; Print".
$ math -noprompt -script test.m
b
$ math -noprompt -script test.m > out
$ cat out
$ ls -l out-rw-rw-r-- 1 tigran tigran 0 May 28 14:27 out
As you can see, if I do NOT redirect the output then the script works fine, i.e. "b" (which is the value of a) is printed to the terminal. But when the output is redirected to a file, nothing is printed, i.e. the file is empty (zero size as shown by ls -l output).
I have found a workaround for this problem: namely, if instead of '-script file' option I pass -run "<<file" then it works as expected:
$ math -noprompt -run "<<test.m" > out
$ cat out
b
Btw, if I want to see the output on the terminal, then I would have to redirect the input to /dev/null, just as I suspected:
$ math -noprompt -run "<<test.m" < /dev/null
b
$
otherwise it would display the prompt (ignoring -noprompt option) and expect interactive input. But this is ok, i.e. it is a reasonable behaviour.