Something like:
// Create the process
Process process = new ProcessBuilder("neato", "-Tplain").start();
// Write to process's stdin
OutputStream osToProcess = process.getOutputStream();
PrintWriter pwToProcess = new PrintWriter(osToProcess);
pwToProcess.write("graph G { node1 -- node2; }"); // for example
pwToProcess.close();
// Read from process's stdout
InputStream isFromProcess = process.getInputStream();
BufferedReader brFromProcess = new BufferedReader(isFromProcess);
// do whatever you want with the reader, then...
brFromProcess.close();
// optionally...
process.waitFor();
I omitted exception handling from this example code -- you'll need to put it in to meet your requirements. It may be sufficient to wrap the whole thing in a try/catch block - it depends what you need.
I validated that neato
reads/writes stdin/stdout at the command line:
$ echo 'graph G { n1 -- n2; }' | neato -Tplain
graph 1 1.3667 1.2872
node n1 0.375 0.25 0.75 0.5 n1 solid ellipse black lightgrey
node n2 0.99169 1.0372 0.75 0.5 n2 solid ellipse black lightgrey
edge n1 n2 4 0.55007 0.47348 0.63268 0.57893 0.7311 0.70457 0.81404 0.81044 solid black
stop