【发布时间】: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'])
干杯!
【问题讨论】:
-
重复:stackoverflow.com/questions/1308755/… 此外,这并不能回答问题的多个应用程序部分,但可能会有所帮助:stackoverflow.com/questions/1081218/…
标签: macos command-line