I recently upgraded maxima from 5.41.0 to 5.43.2 and it broke my code. I could not find a solution that works in both versions the same way. Here is the simplified command line example I am executing:
In version 5.41.0:
user@system:~> maxima -version
Maxima 5.41.0
user@system:~> maxima --very-quiet -r 'display2d: false$ leftjust: true$ ratprint: false$ dispflag: false$ is(equal((a+b)**2 = (a**2 + b**2 + 2*a*b), (a+b)*(a+b) = (a**2 + b**2 + 2*a*b))); ttyoff:true$ quit()$'
true
user@system:~>
In version 5.43.2:
user@system:~> maxima -version
Maxima 5.43.2
user@system:~> maxima --very-quiet -r 'display2d: false$ leftjust: true$ ratprint: false$ dispflag: false$ is(equal((a+b)**2 = (a**2 + b**2 + 2*a*b), (a+b)*(a+b) = (a**2 + b**2 + 2*a*b))); ttyoff:true$ quit()$'
display2d:false
leftjust:true
ratprint:false
dispflag:false
is(equal((a+b)^2 = a^2+b^2+2*a*b,(a+b)*(a+b) = a^2+b^2+2*a*b))
true
ttyoff:true
There are two issues (1) command in v5.43.2 is not quitting maxima after completion to come back to the shell command prompt, where as in v5.41.0, it quits maxima and comes back to the shell command prompt. (2) so, I added quit()$ but the echo of commands is not suppressed with terminator $.
I tried to read the docs to find any info on this, but did not see anything obvious. My objective to execute the passed in command quietly and print only the output of the (last) command. Any help in this matter is really appreciated.
On reviewing the Git log, it appears the behavior of --run-string
(i.e., -r
) was changed in commit fa97979. So the current behavior is considered correct, for what it's worth. That said, to address (1), you can try the --batch-string
option instead of --run-string
.
About (2), although dollar sign suppresses the output, the input is still echoed, and that's what you're seeing. I don't know a way to suppress the input also. At this point I can see a couple of possible approaches.
One is to omit --very-quiet
, so that you get input and output labels. Then grep the output for output labels, or maybe more precisely, grep for an output label following by zero or more lines which do not have a label (to capture multi-line output).
The other approach is to just forget about labels and say with_stdout("/tmp/foo.out", print(...))
where you print the stuff that's relevant to later processing, and then just dump out the file /tmp/foo.out
or whatever it's called afterwards. This is a little clumsier, but probably easier to get exactly what you want in the output file.
I sometimes create bash scripts which look like
cat << EOF > /tmp/foo.mac
someflag: true;
somevar: 1234;
foo: expand (something (something));
EOF
maxima --batch=/tmp/foo.mac
so the bash script creates the Maxima program and then Maxima executes it. That's especially useful if I want to use bash variables (e.g. filenames or something) in the Maxima program, e.g.
f=$1-$2.csv # something I just made up
cat << EOF > /tmp/foo.mac
myinput: openr ("$f");
/* etc etc */
EOF