Reputation: 605
I'm playing around with Flightgear and I'd like a way to launch /Applications/FlightGear.app from a Python script with a specific aircraft, but it's not accepting additional parameters.
This works:
os.system("open /Applications/FlightGear.app/Contents/MacOS/fgfs")
This does, but does not select the aircraft... I've tried both with and without hyphens in front of 'aircraft'.
os.system("open /Applications/FlightGear.app/Contents/MacOS/fgfs --args aircraft=777-200ER")
For references,
(source: flightgear.org)
Upvotes: 2
Views: 589
Reputation: 27077
On OS X, open
is to run an application. To run a command-line program you would just do it like on unix/linux, assuming that /Applications/FlightGear.app/Contents/MacOS/fgfs
is actually a runnable program.
I can't test it for this particular case, but I think you want os.system()
to run exactly what you would type at the command-line prompt. Hence,
os.system("/Applications/FlightGear.app/Contents/MacOS/fgfs --aircraft=777-200ER")
Upvotes: 0
Reputation: 10236
Something like this. Sometimes some of the arguments will have to be combined, depending on their relation to each other.
import subprocess
p = subprocess.Popen(['open', '/Applications/FlightGear.app/Contents/MacOS/fgfs', '--args', 'aircraft=777-200ER'])
if p.wait() != 0:
raise EnvironmentError()
This is basic information that could've been found simply by searching "python run command" in Google. SO isn't just a tool for the lazy.
Upvotes: 2