Skip to content

Commit 750279d

Browse files
t-moralestobiasdiez
andcommitted
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 <tobiasdiez@gmx.de>
1 parent eccfb57 commit 750279d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
1818

1919
### Fixed
2020

21+
- 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)
2122
- 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)
2223
- 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)
2324
- We fixed an issue where non-default previews didn't handle unicode characters. [#5779](https://github.com/JabRef/jabref/issues/5779)

src/main/java/org/jabref/gui/desktop/os/Linux.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515
import org.jabref.gui.externalfiletype.ExternalFileTypes;
1616
import org.jabref.preferences.JabRefPreferences;
1717

18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
1821
import static org.jabref.preferences.JabRefPreferences.ADOBE_ACROBAT_COMMAND;
1922
import static org.jabref.preferences.JabRefPreferences.USE_PDF_READER;
2023

2124
public class Linux implements NativeDesktop {
25+
private static final Logger LOGGER = LoggerFactory.getLogger(Linux.class);
26+
2227
@Override
2328
public void openFile(String filePath, String fileType) throws IOException {
2429
Optional<ExternalFileType> type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType);
@@ -30,7 +35,13 @@ public void openFile(String filePath, String fileType) throws IOException {
3035
viewer = "xdg-open";
3136
}
3237
String[] cmdArray = { viewer, filePath };
33-
Runtime.getRuntime().exec(cmdArray);
38+
Process p = Runtime.getRuntime().exec(cmdArray);
39+
// When the stream is full at some point, then blocks the execution of the program
40+
// See https://stackoverflow.com/questions/10981969/why-is-going-through-geterrorstream-necessary-to-run-a-process.
41+
BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
42+
String line;
43+
line = in.readLine();
44+
LOGGER.debug("Received output: " + line);
3445
}
3546

3647
@Override
@@ -46,7 +57,13 @@ public void openFileWithApplication(String filePath, String application) throws
4657
String[] cmdArray = new String[openWith.length + 1];
4758
System.arraycopy(openWith, 0, cmdArray, 0, openWith.length);
4859
cmdArray[cmdArray.length - 1] = filePath;
49-
Runtime.getRuntime().exec(cmdArray);
60+
Process p = Runtime.getRuntime().exec(cmdArray);
61+
// When the stream is full at some point, then blocks the execution of the program
62+
// See https://stackoverflow.com/questions/10981969/why-is-going-through-geterrorstream-necessary-to-run-a-process.
63+
BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
64+
String line;
65+
line = in.readLine();
66+
LOGGER.debug("Received output: " + line);
5067
}
5168

5269
@Override

0 commit comments

Comments
 (0)