From 5b4af780f42a1bda71b8fa1599609b54466b3b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Morales=20de=20Luna?= Date: Sun, 26 Jan 2020 18:57:26 +0100 Subject: [PATCH] Fix opening pdf with okular in linux (#5253) stream ouput to Logger --- .../java/org/jabref/gui/desktop/os/Linux.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/desktop/os/Linux.java b/src/main/java/org/jabref/gui/desktop/os/Linux.java index e6fbcfc9fe0..00bfc1f4a28 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Linux.java +++ b/src/main/java/org/jabref/gui/desktop/os/Linux.java @@ -18,7 +18,12 @@ import static org.jabref.preferences.JabRefPreferences.ADOBE_ACROBAT_COMMAND; import static org.jabref.preferences.JabRefPreferences.USE_PDF_READER; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class Linux implements NativeDesktop { + private static final Logger LOGGER = LoggerFactory.getLogger(Linux.class); + @Override public void openFile(String filePath, String fileType) throws IOException { Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); @@ -30,11 +35,13 @@ public void openFile(String filePath, String fileType) throws IOException { viewer = "xdg-open"; } String[] cmdArray = { viewer, filePath }; - Process p; - p = Runtime.getRuntime().exec(cmdArray); + Process p = Runtime.getRuntime().exec(cmdArray); + // When the stream is full at some point, then blocks the execution of the program + // See https://stackoverflow.com/questions/10981969/why-is-going-through-geterrorstream-necessary-to-run-a-process. BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream())); String line; line = in.readLine(); + LOGGER.debug("Received output: " + line); } @Override @@ -50,11 +57,13 @@ public void openFileWithApplication(String filePath, String application) throws String[] cmdArray = new String[openWith.length + 1]; System.arraycopy(openWith, 0, cmdArray, 0, openWith.length); cmdArray[cmdArray.length - 1] = filePath; - Process p; - p = Runtime.getRuntime().exec(cmdArray); + Process p = Runtime.getRuntime().exec(cmdArray); + // When the stream is full at some point, then blocks the execution of the program + // See https://stackoverflow.com/questions/10981969/why-is-going-through-geterrorstream-necessary-to-run-a-process. BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream())); String line; line = in.readLine(); + LOGGER.debug("Received output: " + line); } @Override