I'm trying to run the xdg-open test.pdf
command from within a python script, but nothing happens when I execute os.system("xdg-open test.pdf")
even though it outputs code 0, and even though after executing os.system("ls")
it does show the file test.pdf
. I've also tried subprocess.run("xdg-open test.pdf", shell=True)
and subprocess.call(["xdg-open", "test.pdf"])
. On the other hand, if I run xdg-open test.pdf
from the terminal (I'm on Ubuntu), it does open the pdf. What explains this problem and how can I fix it?
Asked
Active
Viewed 481 times
0

user56834
- 244
- 4
- 19
-
Maybe this works for you https://stackoverflow.com/questions/52210112/python-xdg-open – Dennis Jan 28 '21 at 04:29
-
did you try `/usr/bin/xdg-open /full/path/to/test.pdf` ? System may run it in different folder then you expect - or python code may run in different folder then you expect (check `os.getcwd()` and `os.system("pwd")` to see `Current Working Directory`) . BTW: you should get the same result with `import webbrowser` and `webbrowser.open("test.pdf")` because this module uses `xdg-open` to open url with default web browser. – furas Jan 28 '21 at 05:10