python subprocess:如何在OS X上运行应用程序?

时间:2012-10-25 15:35:51

标签: python macos osx-snow-leopard subprocess

我正在将一个Windows应用程序移植到OS X 10.6.8。这对我来说是一个新平台,我面临一些困难。

该应用程序是一个小型的Web服务器(瓶子+服务员),由于子进程调用,它启动了一个浏览器(基于chrome嵌入式框架)。

浏览器是一个应用程序文件,从gui启动时运行正常。

我这样推出:

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

不幸的是,OSError: permission denied失败了。

我尝试使用sudo运行脚本,结果相似。

我可以使用以下命令从shell启动应用程序:

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

但是

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

因以下错误而失败

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

知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:5)

文件cefclient.app实际上是一个目录(具体是application bundle),而不是应用程序可执行文件。真正的可执行文件位于包内,其路径类似于Contents/MacOS/executable_name。所以要启动它,你会这样做:

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

答案 1 :(得分:1)

或者,

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

只是想要控制stdin / stdout或启动应用程序是否足够。