- public GnuplotSession newSession(Path workingDirectory, Path stdout, Path stderr) throws IOException {
- Process process = new ProcessBuilder(executable.toString())
- .directory(workingDirectory.toFile())
- .start();
- return new GnuplotSession(workingDirectory, stdout, stderr, process);
+ private ProcessBuilder buildSessionProcess(Path workingDirectory, Path stdout, Path stderr, boolean redirectErrorStream) {
+ ProcessBuilder builder = new ProcessBuilder(executable.toString())
+ .directory(workingDirectory != null ? workingDirectory.toFile() : null)
+ .redirectErrorStream(redirectErrorStream);
+ if (stdout != null)
+ builder.redirectOutput(stdout.toFile());
+ if (stderr != null)
+ builder.redirectError(stderr.toFile());
+ return builder;
+ }
+
+ public GnuplotSession newSession(Path workingDirectory, Path stdout) throws IOException {
+ return newSession(workingDirectory, stdout, null, true);
+ }
+
+ public GnuplotSession newSession(Path workingDirectory, Path stdout, Path stderr, boolean redirectStderr) throws IOException {
+ return new GnuplotSession(workingDirectory, stdout == null, stderr == null,
+ buildSessionProcess(workingDirectory, stdout, stderr, redirectStderr).start());