[Python] How to open a file with xdg-open in a python script? (wrong application used)

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to open a file on an Ubuntu machine from within Python script. However, xdg-open will always use another application (the wrong one) when started from the python script, while it will use the correct one when started from the shell.

    I tried with the following commands:

    subprocess.Popen([f"xdg-open {file_path}"])
    subprocess.Popen([f"xdg-open {file_path}"], user="user", env=os.environ, shell=True)


    Any idea, what to do?

    Continue reading...

Compartilhe esta Página