Charlie
Charlie

Reputation: 11

Opening another file from Python and terminate script

I am trying to figure out the best solution to accomplish this. Basically, I want to open another program from Python (doesn't matter, could be an image, executable, etc). I have tried os.system and subprocess.call however both will not terminate the script after, and will instead wait for a return. I have looked at os.execl, and it seems to close to what I need, but I am not sure if I understand the arg's as I always get exec format errors and invalid arguments. I am not even sure if this is the proper function for what I need. Any help would be appreciated.

I have tried using subprocess.call and subprocess.Popen using something similar to this:

import subprocess
subprocess.Popen("B:\test.txt")

and it ends up with the following error:

WindowsError: [Error 5] Access is denied.

Upvotes: 1

Views: 809

Answers (2)

Teddy
Teddy

Reputation: 6163

os.execlp("start", r"B:\test.txt")

(That's for Windows. On a Unix system running X11, you'd do this:)

os.execlp("xdg-open", r"B:\test.txt")

Upvotes: 1

JBernardo
JBernardo

Reputation: 33397

Use subprocess.Popen[docs]

Just don't call communicate on the resulting object.

Upvotes: 1

Related Questions