1

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.

3
  • What do you mean by "could be an image"?
    – Keith
    Commented Sep 23, 2011 at 4:39
  • @Keith: As in it could be an image file, a text file, an executable file. Anything I wish to open.
    – Charlie
    Commented Sep 23, 2011 at 4:50
  • 1
    related: stackoverflow.com/questions/1679798/…
    – jfs
    Commented Sep 23, 2011 at 8:12

2 Answers 2

1

Use subprocess.Popen[docs]

Just don't call communicate on the resulting object.

3
  • I should of also mentioned that using subprocess.Popen gives me access denied errors on Windows and will not work.
    – Charlie
    Commented Sep 23, 2011 at 3:49
  • 1
    @Charlie: I should also mention that "access denied errors" is vague. If you have a specific error message, then please, rewrite your question to (1) include your code and (2) include your specific error message. We might be able to actually solve your actual problem if we knew what it was.
    – S.Lott
    Commented Sep 23, 2011 at 3:55
  • @S. Lott I should also mention when I mean Access Denied I mean WindowsError: [Error 5] Access is denied. The code is as follows: import subprocess; subprocess.Popen("B:\test.txt")
    – Charlie
    Commented Sep 23, 2011 at 4:49
1
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")

Not the answer you're looking for? Browse other questions tagged or ask your own question.