From 750279d5c19850ab4930abadd3bc515f20a9e948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Morales=20de=20Luna?= <39190016+t-morales@users.noreply.github.com> Date: Sun, 26 Jan 2020 20:01:40 +0100 Subject: [PATCH] Fix opening pdf with okular in linux (#5253) (#5855) * Fix opening pdf with okular in linux (#5253) * Fix opening pdf with okular in linux (#5253) stream ouput to Logger * Fix checkstyle Co-authored-by: Tobias Diez --- CHANGELOG.md | 1 + .../java/org/jabref/gui/desktop/os/Linux.java | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf9dd437392..aacb7819b24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ### Fixed +- We fixed and issue where pdf files will not open under some KDE linux distributions when using okular. [#5253](https://github.com/JabRef/jabref/issues/5253) - We fixed an issue where the Medline fetcher was only working when JabRef was running from source. [#5645](https://github.com/JabRef/jabref/issues/5645) - We fixed some visual issues in the dark theme. [#5764](https://github.com/JabRef/jabref/pull/5764) [#5753](https://github.com/JabRef/jabref/issues/5753) - We fixed an issue where non-default previews didn't handle unicode characters. [#5779](https://github.com/JabRef/jabref/issues/5779) 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 dd45135a6b1..a39c6e335d2 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Linux.java +++ b/src/main/java/org/jabref/gui/desktop/os/Linux.java @@ -15,10 +15,15 @@ import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.preferences.JabRefPreferences; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import static org.jabref.preferences.JabRefPreferences.ADOBE_ACROBAT_COMMAND; import static org.jabref.preferences.JabRefPreferences.USE_PDF_READER; 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,7 +35,13 @@ public void openFile(String filePath, String fileType) throws IOException { viewer = "xdg-open"; } String[] cmdArray = { viewer, filePath }; - 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 @@ -46,7 +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; - 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