2
votes

I have a Process in my Java app, made using ProcessBuilder, that runs the command line version of Octave. Everything works fine. However, when I send a plot command to Octave, it does not open a window showing the plot, as it does if you do it in a normal console. There is no error message or anything else. Just no plot.

Is there a way to change that?

Regards

Thorsten

1
What OS and Octave version are you using? - Andrew Janke
Win10 Enterprise and Octave 5.1.90 - Thorsten Schmitz

1 Answers

0
votes

I found the time to make a small sample to show this:


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

class OctavePlotTest {

    public static int main(String[] args) {

        ProcessBuilder builder = new ProcessBuilder();
        builder.command("octave-cli");
        builder.redirectErrorStream(true);
        
        Process process;
        try {
            process = builder.start();

            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream ()));
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));

            String line;

            // Check that Octave is really running and streams are read from / written to
            writer.write("1+1");
            writer.newLine();

            // Try to plot
            writer.write("plot(sin(0:0.1:2*pi))");
            writer.newLine();
            
            writer.flush();

            while ((line = br.readLine()) != null)
            {
                System.out.println(line);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

plot(sin(0:0.1:2*pi)) works if you run it in Octave's command line version, but not when called via the Java Process object.