OSX: running multiple instances of the application and passing command line arguments to them

There is a program that I need to run several times and pass different arguments to it every time. For this, I tried to write 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 use "open" is the ability to run the application several times. Is the correct command to use open? Any suggestions on how to do this? Working with linux / mac is very new to me.

Thank!

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

Hurrah!

+4
command-line macos
Oct 15 '09 at 2:14
source share
1 answer

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

 os.system('open -n ./AppName.app --args -AppCommandLineArg') 
+1
Oct 15 '09 at 2:22
source share



All Articles