Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
910 views
in Technique[技术] by (71.8m points)

xcode - How to run command-line application from the terminal?

I'm a recent convert from Windows to Macbook Pro. I am getting use to Xcode. One thing that I would enjoy is when running a debug application in the terminal. Currently, I have to press Command+R for it to compile and run in Xcode. To have the application run in the terminal, I have to do an additional step by opening the Products folder, right click the application, then 'Open as Exterior Editor'. Then the terminal opens and runs the program.

I would like this behavior to work automatically by pressing Command+R. It seems to me like there would be a setting to direct the output.

Are there any steps to accomplish this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First, make a new scheme (or edit the current one) and change the executable to Terminal.app:

Scheme Info

Then, under the "Arguments" tab, make sure "Base Expansions On" is set to your App. Then put open -a ${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}

Scheme Arguments? ?

The command will get expanded to something like open -a /Users/Me/Library/Developer/Xcode/DerivedData/MyProj-abcdefghijklmnopqrrstuvwxyz/Build/Products/Debug-iphonesimulator/Universal.app

open -a is how you open an App from the command line.

Edit: Use ${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME} instead (see comments).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...