Mac应用程序的可执行路径

发布于 2024-10-05 02:33:32 字数 2093 浏览 8 评论 0原文

在 py2app/Mac 应用程序包中,有没有办法通过传递不同的命令行参数来从应用程序内生成同一应用程序的另一个实例?

或者给定一个 mac 应用程序包,我如何从命令行运行它并传递一些参数?

编辑1:分叉是一个有限的选项,它可能无法与应用程序捆绑的第3方可执行文件一起使用+我需要在Mac和Windows上运行它。
Edit2:问题是如何使用子进程模块运行捆绑的Python脚本

详细信息:

我正在使用 py2app 为我的应用程序生成应用程序包。我的应用程序有两个部分

  1. MainApp:这是 UI
  2. BackgroundApp:一个后台进程,它执行真正的工作

MainApp 和 BackgroundApp 都已实现为 python 脚本,实际上它们是具有不同命令行的相同 python 脚本,例如

python myapp.py
python myapp.py --backgroundprocess

所以当我运行 python myapp.py 它会根据程序路径自动启动后台进程,但由于我现在已将我的应用程序捆绑为 py2app,所以我不确定应该调用并传递 --backgroundprocess 选项?

我尝试过的

  1. $ open MyApp.app/ 这会打开应用程序,但我无法将参数传递给它,因为它们将是 open 命令的参数,不会传递给我的app

  2. < p>$ MyApp.app/Contents/MacOS/MyApp --backgroundprocess 打开应用程序,但不会打开后台进程,因为参数似乎没有传递给应用程序

它也会引发错误

  Traceback (most recent call last):
  File "/Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/run.py", line 4, in <module>
    from renderprocess import RenderEngineApp
  File "renderprocess/RenderEngineApp.pyc", line 6, in <module>
  File "wx/__init__.pyc", line 45, in <module>
  File "wx/_core.pyc", line 4, in <module>
  File "wx/_core_.pyc", line 18, in <module>
  File "wx/_core_.pyc", line 11, in __load
ImportError: dlopen(/Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/lib/python2.5/lib-dynload/wx/_core_.so, 2): Library not loaded: @executable_path/../Frameworks/libwx_macud-2.8.0.dylib
  Referenced from: /Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/lib/python2.5/lib-dynload/wx/_core_.so
  Reason: Incompatible library version: _core_.so requires version 7.0.0 or later, but libwx_macud-2.8.0.dylib provides version 2.6.0

结论:看起来可能不可能 使用命令行在 OS X 上启动应用

< code>open 不排除参数。

In a py2app/Mac Application Bundle, is there a way to spawn another instance of same app from within the app, by passing different command line arguments?

or given a mac app bundle, how can I run it from command line and pass some arguments too?

Edit1:forking is a limited option, which may not work with 3rd party executables bundle with app+I need to run this on mac and windows.
Edit2: Question is how to run a a bundled python script using subprocess module

Details:

I am using py2app to generate a app bundle for my appilcation. My application has two parts

  1. MainApp: which is the UI
  2. BackgroundApp: a background process, which does the real job

Both MainApp and BackgroundApp have been implemented as python script and actually they are the same python script with different commandline e.g.

python myapp.py
python myapp.py --backgroundprocess

So when I run python myapp.py it automatically starts background process based on program path, but as I have now bundled my app as py2app I am not sure what executable I should be calling and passing --backgroundprocess option?

What I have tried

  1. $ open MyApp.app/ this opens the app but I can't pass the arguments to it, as they will be arguments for open command and will not be passed to my app

  2. $ MyApp.app/Contents/MacOS/MyApp --backgroundprocess opens the app but not the backgroun process as it seems arguments are not being passed to app

also it throws error

  Traceback (most recent call last):
  File "/Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/run.py", line 4, in <module>
    from renderprocess import RenderEngineApp
  File "renderprocess/RenderEngineApp.pyc", line 6, in <module>
  File "wx/__init__.pyc", line 45, in <module>
  File "wx/_core.pyc", line 4, in <module>
  File "wx/_core_.pyc", line 18, in <module>
  File "wx/_core_.pyc", line 11, in __load
ImportError: dlopen(/Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/lib/python2.5/lib-dynload/wx/_core_.so, 2): Library not loaded: @executable_path/../Frameworks/libwx_macud-2.8.0.dylib
  Referenced from: /Users/agyey/projects/myapp/release4.26/py2exe/dist/MyApp.app/Contents/Resources/lib/python2.5/lib-dynload/wx/_core_.so
  Reason: Incompatible library version: _core_.so requires version 7.0.0 or later, but libwx_macud-2.8.0.dylib provides version 2.6.0

Conclusion: it looks like it may not be possible
Launch an app on OS X with command line

open doesn't except arguments.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏末的微笑 2024-10-12 02:33:32

如何查找 cwd 并执行任意提供的二进制文件
首先将二进制文件放在 AppName.app/Contents/Resources 中,然后从 python 脚本运行此代码:

import subprocess
process=subprocess.Popen((os.getcwd() + "/3rd_party_binary","--subprocess")) 
process.poll() # is running?

如何正确生成 python 应用程序的两个版本

Fork 是在 MacOSX (unix) 上执行此操作的旧尝试方法)

#!/usr/bin/env python
import os, sys

pid = os.fork()
if pid:
    # we are the parent
    background_process.start()
    os.waitpid(pid, 0) # make sure the child process gets cleaned up
else:
    # we are the child
    gui_app.start()
    sys.exit(0)

print "parent: got it; text =", txt

Python 中的多处理 显然也可以在 Windows 上运行我想你会很感兴趣(?)。

Howto find cwd and execute an arbitrary supplied binary
First place the binary in AppName.app/Contents/Resources then run this code from the python script:

import subprocess
process=subprocess.Popen((os.getcwd() + "/3rd_party_binary","--subprocess")) 
process.poll() # is running?

Howto properly spawn two version of your python app

Fork is the old tried way to do this on MacOSX (unix)

#!/usr/bin/env python
import os, sys

pid = os.fork()
if pid:
    # we are the parent
    background_process.start()
    os.waitpid(pid, 0) # make sure the child process gets cleaned up
else:
    # we are the child
    gui_app.start()
    sys.exit(0)

print "parent: got it; text =", txt

Multiprocessing in Python is apparently something that works on windows as well which I guess would be interesting to you(?).

甩你一脸翔 2024-10-12 02:33:32

创建一个应用程序,然后只需调用该应用程序的 --bakgroundprocess,然后为后台进程标志创建一个快捷方式。或者两个不同的应用程序文件。以太币是个好办法

Create one application then just call the --bakgroundproccess for the app, then create a shortcut for the backgroundprocess flag. Or two different app files. Ether is a good way

巷雨优美回忆 2024-10-12 02:33:32

我无法让 py2app 工作,但应用程序的可执行文件位于 AppName.app/Contents/MacOS/AppName 中。您可以在AppName.app/Contents/Info.plist文件中检查CFBundleExecutable键,它指向中的捆绑包可执行文件AppName.app/Contents/MacOS 文件夹。

因此,您可以将其称为 AppName.app/Contents/MacOS/AppName --backgroundprocess

如果您希望 BackgroundApp 不带任何参数运行后台进程,有两种选择:a) 从 python 脚本制作包,该脚本不带任何参数运行后台进程; b) 将 Info.plist 文件中的 CFBundleExecutable 更改为 BackGroundApp_shell,并制作 shell 脚本 Contents/MacOS/BackgroundApp_shell 包含以下内容:

#!/bin/sh

`dirname "$0"`/BackgroundApp --backgroundprocess

假设可执行文件是 BackgroundApp

I couldn't get py2app working, but the applications' executable are located in AppName.app/Contents/MacOS/AppName. You can check in AppName.app/Contents/Info.plist file for key <key>CFBundleExecutable</key>, it points to the bundles executable in AppName.app/Contents/MacOS folder.

So you can call it as AppName.app/Contents/MacOS/AppName --backgroundprocess.

If you want the BackgroundApp to run the background process without any arguments, there are two options: a) make the bundle from python script, which runs the background process without any arguments; b) change <key>CFBundleExecutable</key> in Info.plist file to say BackGroundApp_shell, and make a shell script Contents/MacOS/BackgroundApp_shell of the following content:

#!/bin/sh

`dirname "$0"`/BackgroundApp --backgroundprocess

assuming the executable is BackgroundApp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文