【问题标题】:OSX: Launching multiple instances of an app and passing them command line argsOSX:启动应用程序的多个实例并将其传递给命令行参数
【发布时间】:2009-10-17 03:25:26
【问题描述】:

有一个程序我需要多次启动并每次传递不同的参数。为此,我尝试编写一个简单的 python 脚本,如下所示:

import sys, os
from os.path import join

# This works, but will not launch twice
os.system('./AppName.app -AppCommandLineArg')

# This allows launching two instances but without command line arguments
os.system('open --new --background ./AppName.app')

# Attempt #1
os.system('open --new --background ./AppName.app -AppCommandLineArg')

# Attempt #2
os.system('open --new --background "./AppName.app -AppCommandLineArg"')

# Attempt #3
os.system('open --new --background "./AppName.app/Contents/MacOS/AppName -AppCommandLineArg"')

我使用“打开”的原因是能够多次启动应用程序。 'open' 是使用正确的命令吗?关于如何做到这一点的任何建议?使用 linux/mac 对我来说非常陌生。

谢谢!

编辑 - 这是为我解决问题的代码:

p0   = subprocess.Popen(['./AppName.app/Contents/MacOS/AppName', '-AppCommandLineArg'])
p1   = subprocess.Popen(['./AppName.app/Contents/MacOS/AppName', '-AppCommandLineArg'])

干杯!

【问题讨论】:

标签: macos command-line


【解决方案1】:

是的,open 是在 Mac OS X 上启动应用程序的正确方法。有关详细信息,请参阅man page。我现在不在 Mac 上,所以我无法对此进行测试,但我相信以下应该可以工作:

os.system('open -n ./AppName.app --args -AppCommandLineArg')

【讨论】:

  • open 不采用命令行参数。有关选项/详细信息,请参阅我的回复中的链接。
  • @psychotik:根据我链接到的手册页,是的,至少在 OS X 10.6 上是这样
  • 我试过了,但我得到了这个错误消息:打开:无法识别的选项 `--args' 打印出有关“打开”的帮助时,“--args”不显示为标志任何一个。我确实看到你指向我的页面有那个标志。知道我的终端中的“打开”如何不支持该标志吗?
  • 这个标志可能是 10.6 中的新标志 - 我很高兴看到他们添加了它。不过,直到几年后它才会得到太多采用——我怀疑 10.5 将在一段时间内仍然是最受欢迎的 OSX 版本。 OP - 你可能正在使用 10.5
  • 有趣!是的,似乎在 10.6 中实现了 --args。
猜你喜欢
  • 1970-01-01
  • 2010-09-14
  • 1970-01-01
  • 2017-05-30
  • 2020-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多