-1

The OS module on Windows or MacOS has the following;

os.system("start APPLICATION.EXTENSION filename") 

Will open filename (I mean actually open rather than python open, as if you did Right mouse>open) if its in the same folder as the python file on windows. The MacOS version is;

os.system("open filename")

What I'm asking for is the linux equivalent. If you know of a different module or method I'm open to anything.

All I've been able to find online is the usual

file = filepath
open(file)
read(file)

And these are absolutely not what I want to achieve. Any and all help is much appreciated, you might be able to tell this issue is getting to me.

3
  • I know what you mean, but I also don't know exactly what you are aiming to achieve. This type of open will launch the GUI or other app associated with the file extension or the file itself. So Python won't know anything about that. Furthermore, unless it has changed recently, the open semantics on Windows can be problematic. In a DOS batch file, if you start a text.txt while Notepad is open, the call returns right away to the batch. If Notepad was not open, and had to be started, the batch blocks at that line, until Notepad is closed. Commented Jul 3, 2020 at 18:31
  • 1
    Rather than asking if just Python can do this, check first what Linux itself supports in this regard, how it is done, who provides the service (it probably wouldn't be useful for you if only a distribution's file manager supported that functionality). Welcome aboard, and sorry for whoever felt they absolutely needed to downvote. Some folk on SO can be a bit annoying with their anonymous, no-feedback downvoting. But I fear that, at this stage, this is not a Python question, it's an OS question. Commented Jul 3, 2020 at 18:35
  • 1
    This has nothing to with Python, as os.system simply runs a shell command using the default shell. Whether any particular Linux distribution has an equivalent of Windows start or macOS open is independent of Python or any other programming language. Commented Jul 3, 2020 at 20:06

1 Answer 1

1

I'm on Linux Mint 19.3 and did it with subprocess's Popen.

import subprocess
subprocess.Popen(['APP_COMMAND', '~/file.txt'])

Additional detail and variations can be found: Calling an external command from Python

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.