0

I'm trying to open a PDF file in Linux with the xdg-open command in java.

String[] command = {"xdg-open","\""+path+"\""}
Process p = Runtime.getRuntime().exec(command,null);
p.waitFor();

When I run the code in terminal nothing happens even tho if I type it in terminal:

xdg-open path

it opens the PDF. Any ideas whats wrong?

Tiago Martins Peres
  • 12,598
  • 15
  • 77
  • 116
  • Maybe this helps? [https://stackoverflow.com/a/40569083/2633917](https://stackoverflow.com/a/40569083/2633917) – tobifasc Oct 18 '18 at 10:20

1 Answers1

1

You should not escape the path: if the program was called, it was with an invalid path ("path" and not path).

String[] command = {"xdg-open", path}

The Runtime.getRuntime().exec(command,null); will use ProcessBuilder internally which, in the case of Linux, should invoke the system command execve.

NoDataFound
  • 10,327
  • 29
  • 56