OSX:启动应用程序的多个实例并传递命令行参数 [英] OSX: Launching multiple instances of an app and passing them command line args

查看:344
本文介绍了OSX:启动应用程序的多个实例并传递命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  import sys,os 
从os.path import join

#这样工作,但不会启动两次
os.system('./ AppName.app -AppCommandLineArg')

#这允许启动两个实例但没有命令行参数
os.system('open --new --background ./AppName.app')

#尝试#1
os.system --new --background ./AppName.app -AppCommandLineArg')

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

#尝试#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'])
/ pre>

干杯!

解决方案

c> open 是在Mac OS X上启动应用程序的正确方法。请参阅手册页了解更多信息。我现在不在Mac上,所以我不能测试这个,但我相信以下应该工作:

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


There is a program I need to launch multiple times and pass it different arguments each time. To do this I tried writing a simple python script as follows:

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"')

The reason I'm using 'open' is to be able to launch the app multiple time. Is 'open' the correct command to use? Any suggestions on how to do this? Working with linux/mac is very new to me.

Thanks!

Edit - Here is the code that solved the problem for me:

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

Cheers!

解决方案

Yes, open is the correct way of launching applications on Mac OS X. See the man page for more information. I'm not on a Mac right now, so I can't test this, but I believe the following should work:

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

这篇关于OSX:启动应用程序的多个实例并传递命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆