fishbacp
fishbacp

Reputation: 1263

Subprocess: Permission and No such file or directory error messages

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

Answers (1)

Maurice Meyer
Maurice Meyer

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

Related Questions