Running a command-line program from Terminal


#1

The book say:

[quote]If you are running this from bash, you could just type in the arguments on the command line.
$ Affirmation Aaron 4
[/quote]

When I do this, I get the following error:

If there’s a particular directory I need to be in in order to run the command, I can’t figure out what it is. What am I doing wrong?

Thanks! Love the book.


#2

I was able to run it successfully from terminal by using the full crazy-long path to Affirmation:

$ ./Users/Myname/Library/Developer/Xcode/DerivedData/Affirmation-bjjnqsedfsrcnifhouurxomdhuwg/Build/Products/Debug/Affirmation Aaron 4

But surely this cannot be the only way. Right?


#3

If you are in the same directory as the program, you don’t need to type in the full path; just enter the program’s name preceded by a “./” (a dot and a back slash),
like this:
./Affirmation Aaron 4

Alternatively you can modify the search list, but there is no real reason to do so.


#4

ibex10,

Thanks for your response. cd’ing through that insane directory structure is just as cumbersome. Is that truly the directory I need to run the program from? There isn’t some other simpler path that xcode builds to?

I don’t know what you mean by “modify the search list”.


#5

Oops: that should have been path search list.

Yes. However, you don’t have to descend that long-winding path manually; Xcode can take you there with one click; then you can open the Terminal application from the Finder very easily.

In Xcode’s Navigator’s Pane, under Products, select the executable; show the File Inspector, and click on the tiny navigation arrow (at the end of the Full Path) to land in the directory; then go one level up in the Finder, and then Command-click on the Debug or Release and select New Terminal at Folder from the Finder menu that pops up; a terminal window should open; do ls; you should see your program now.


#6

[quote=“ibex10”]
In Xcode’s Navigator’s Pane, under Products, select the executable; show the File Inspector, and click on the tiny navigation arrow (at the end of the Full Path) to land in the directory; then go one level up in the Finder, and then Command-click on the Debug or Release and select New Terminal at Folder from the Finder menu that pops up; a terminal window should open; do ls; you should see your program now.[/quote]
Do you mean Control-click (to get the contextual menu) here? That option New Terminal at Folder is not listed for me. I just dragged and dropped the executable into the Terminal window for the same effect, but I don’t seem to have the same contextual menu items that you do.


#7

You are right: that should be Control-click.

As for the New Terminal at Folder item, you need to enable it in the Finder’s Services menu.


#8

Aha, hidden away in the Keyboard pane of System Preferences. Nice.