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.

Charlie
  • 11
  • 2

2 Answers2

1

Use subprocess.Popen[docs]

Just don't call communicate on the resulting object.

JBernardo
  • 32,262
  • 10
  • 90
  • 115
  • I should of also mentioned that using subprocess.Popen gives me access denied errors on Windows and will not work. – Charlie Sep 23 '11 at 03: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 Sep 23 '11 at 03: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 Sep 23 '11 at 04: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")
Teddy
  • 6,013
  • 3
  • 26
  • 38