python subprocess: how to run an app on OS X?

寵の児 提交于 2019-12-11 18:34:34

问题


I am porting a windows application to OS X 10.6.8. It is a new platform for me and I am facing some difficulties.

The application is a small webserver (bottle+waitress) which is starting a browser (based on chromium embedded framework) thanks to a subprocess call.

The browser is an app file and runs ok when started from gui.

I am launching it this way:

subprocess.Popen([os.getcwd()+"/cef/cefclient.app", '--url=http://127.0.0.1:8100'])

Unfortunately, this fails with OSError: permission denied.

I tried to run the script with a sudo with similar result.

I can launch the app from shell with the following command:

open -a "cef/cefclient.app" --args --url-http://127.0.0.1:8100

But

subprocess.Popen(['open', '-a', os.getcwd()+'/cef/cefclient.app', '--args', '--url-http://127.0.0.1:8100'])

fails with the following error

FSPathMakeRef(/Users/.../cefclient.app) failed with error -43.

Any idea how to fix this issue?


回答1:


The file cefclient.app is actually a directory (an application bundle, specifically), not the application executable. The real executable is located inside the bundle, with a path like Contents/MacOS/executable_name. So to launch it, you'd do this:

subprocess.Popen([os.getcwd()+"/cef/cefclient.app/Content/MacOS/executable_name",
                  "--url=http://127.0.0.1:8100"])



回答2:


Alternatively,

os.system('open -a "cef/cefclient.app" --args --url-http://127.0.0.1:8100')

Just depends if you want to control stdin / stdout or if starting the app is enough.



来源:https://stackoverflow.com/questions/13072158/python-subprocess-how-to-run-an-app-on-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!