2

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,

pic
(source: flightgear.org)

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I spent several minutes searching around doing my homework and read similar answers but did not realise that the difference of running it with open and without. Found it now that I stopped searching for 'how to open an application'...
The Python documentation is very good. Assume that if you haven't ended-up there, you haven't searched for the right thing, and should just go there directly. Though, in all of the projects and time that I've spent on Python, I've never had to go to the Python website directly. Anyways, be sure to accept the answer.
Tried the code and it's not reading off the parameters, launches straight into the default aircraft, even after appending the --aircraft necessary in Andrew's answer.
0

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

5 Comments

>>> os.system("open /Applications/FlightGear.app/Contents/MacOS/fgfs aircraft=777-200ER") The file /aircraft=777-200ER does not exist. 256 :(
No, the manual page for open() clearly describes the --args argument.
To be clear: this answer works? If so, please upvote!
@AndrewJaffe it works when I also append -- in front of aircraft. I've used my upvote, two others must have downvoted :(
Thanks -- I added the -- where it belongs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.