Reputation: 1263
I'm using Python 3.7 with Idle on a Mac running OS 10.15.4 and am trying to learn the basics of subprocess, with little success despite much effort.
import subprocess
subprocess.Popen('/Applications/Safari.app')
This results in a lengthy error message ending with
PermissionError: [Errno 13] Permission denied: '/Applications/Safari.app'
Removing the first backslash and instead using
subprocess.Popen('Applications/Safari.app')
results in
FileNotFoundError: [Errno 2] No such file or directory: 'Applications/Safari.app': 'Applications/Safari.app'
When I replace Safari with TextEdit, which I'm more interested in using, I receive the second of these error messages regardless of whether I include a backslash.
Upvotes: 1
Views: 425
Reputation: 18136
Use the full path to the executable:
subprocess.Popen('/Applications/Safari.app/Contents/MacOS/Safari')
<subprocess.Popen object at 0x1023414f0>
Alternatively there is the webbrowser
module:
>>> import webbrowser
>>> s = webbrowser.get('safari')
>>> s.open('https://google.com')
Upvotes: 1