Calling Maxima $diff from java



Another way to access Maxima from Java is to use stream connections.
There are two possible ways: Process and Socket Objects both have
methods to get the streams.

In this case you don't need to know Maxima internals. You communicate
as a normal user.

Here is a short demo of the socket version. I use netcat as the socket
server and Maxima connects to this server as a client by -s
portnumber.

First terminal (the listening server):
volker at uvw32:~$ nc -l 4711
pid=6795
(%i1) diff(sin(x), x);

(%o1)                               cos(x)
(%i2) for n thru 3 do (system("sleep 1"), print(n));

1
2
3
(%o2)                                done
(%i3) quit();
volker at uvw32:~$

Second terminal (the Maxima core as a client):
volker at uvw32:~$ maxima -q -s 4711
Connecting Maxima to server on port 4711
volker at uvw32:~$

netcat has independend input and output threads. That's what I would
recommend if you choose this way for Java. So you don't have to worry
how Maxima finishes its ouput (there is no linebreak at the end!). And
you don't need to know when it finishes. E.g. the above loop prints
are displayd as intended.

Volker van Nek