Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

Running gnuplot on java

I′m running a java project using gnuplot to generate charts in pdf but I want to save those files in another folder outside my working directory. Is that possible?

I have this for now

Process proc = Runtime.getRuntime().exec("gnuplot test.gp");
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(proc.getInputStream()));

        String line = "";
        while ((line = reader.readLine()) != null) {
            System.out.print(line + "
");
        }

        proc.waitFor();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In gnuplot console check help command line options. There is the option -e.

You need to have the following argument for exec() in Java.

"gnuplot -e myOutput='<YourPDF>' test.gp"

where you have to replace <YourPDF> with your path. Since I do not know Java, the Java-people have to tell you how you get this done.

A minimal gnuplot script would for example look like the following:

set term pdfcairo
set output myOutput
plot sin(x)   # or whatever
set output

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...