Amazon.com Widgets executing Obj-C/Xcode from command line (osx)
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 04:07:40 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Help!!!
| | |-+  executing Obj-C/Xcode from command line (osx)
Pages: [1]   Go Down
Print
Author Topic: executing Obj-C/Xcode from command line (osx)  (Read 587 times)
SiriusA
Newbie
*
Posts: 22






« on: August 20, 2009, 01:38:10 PM »

[I did a search of this forum but didn't see an answer]

I'm working on Chapter 13 now and I need to execute my code from the command line (in order to pass arguments there). From what I've looked into, I believe that XCode produces an app with each build under {project}/build/Debug/{project}

I've tried to execute this by going into terminal and just putting that project/file/app name, but terminal responds with "command not found."

Can anyone enlighten me on the proper way to execute from the command line?

Thanks!
Logged
rgronlie
Global Moderator
Full Member
*****
Posts: 212







« Reply #1 on: August 20, 2009, 02:57:47 PM »

I ran into the same thing. It seems OSX will only look for commands that can be found in one of the locations specified in the PATH environment variable. Even if you are currently in the directory of the app you are trying to run.

If there is a way to get it to automatically look in the current directory I'd like to know how to get it to do that.

To view the PATH variable type

echo $PATH

So you would need to include the path to your app. By default the terminal starts up with your home directory.

So in my case it would be...

'Documents/Development/Programming in Objective-C/Program 13.1/build/debug/Program 13.1'

to run the app directly... or

cd 'Documents/Development/Programming in Objective-C/Program 13.1/build/debug/'
'./Program 13.1'

To change the current directory to the app's directory and then run it.

Notice the command argument is in single quotes (I believe double quotes work as well). If your command line contains spaces in it you will need to use these quotes or the command will be split into multiple arguments instead of the single argument you intended. This could be one cause of the "command not found"

« Last Edit: August 20, 2009, 03:02:33 PM by rgronlie » Logged

Sanity: Minds are like parachutes. Just because you've lost yours doesn't mean you can borrow mine.
SiriusA
Newbie
*
Posts: 22






« Reply #2 on: August 20, 2009, 08:07:02 PM »

thanks, rgronlie!

I do know some basic UNIX commands (very basic) and was able to cd from where terminal started me into the directory containing the executable (/Debug). but when there, I still couldn't get the app to run by calling it directly.

HOWEVER, when I backed up a directory and put in /Debug/chap13.prob8 it executed!

I don't understand what you meant about the PATH variable. When I executed echo $PATH at the command line I got: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

How am I to use this information?

Thanks!
Logged
rgronlie
Global Moderator
Full Member
*****
Posts: 212







« Reply #3 on: August 20, 2009, 11:22:14 PM »

Quote
I don't understand what you meant about the PATH variable. When I executed echo $PATH at the command line I got: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

That was just for a little background information. What that shows you is where OSX will look for programs to execute if you don't specifically tell it where the program is.. as you did by typing /Debug/chap13.prob8

The paths are colon (Smiley delimited so you can see that OSX will only look in /usr/bin, /bin, /usr/sbin, /sbin, usr/local/bin or /usr/X11/bin for a program. This only applies to the command line... not program launching from Finder.

So if you make a handy command line tool you can place it in "usr/local/bin" for example and the program will launch without the need to supply it's path to OSX.
Logged

Sanity: Minds are like parachutes. Just because you've lost yours doesn't mean you can borrow mine.
SiriusA
Newbie
*
Posts: 22






« Reply #4 on: August 22, 2009, 11:01:39 AM »

cool. much obliged!
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.