Skip to content

Commit

Permalink
Fix opening pdf with okular in linux (JabRef#5253) stream ouput to Lo…
Browse files Browse the repository at this point in the history
…gger
  • Loading branch information
t-morales committed Jan 26, 2020
1 parent 98edbfb commit 5b4af78
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExternalFileType> type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType);
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5b4af78

Please sign in to comment.