Amazon.com Widgets Question for Steve ( or anyone) about 16.6 output
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 11:45:51 AM
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
| |-+  Answers to Exercises
| | |-+  Chapter 16 (Moderator: sgg_admin)
| | | |-+  Question for Steve ( or anyone) about 16.6 output
Pages: [1]   Go Down
Print
Author Topic: Question for Steve ( or anyone) about 16.6 output  (Read 2189 times)
mdeh
Full Member
***
Posts: 166






« on: February 10, 2009, 10:13:37 PM »

Steve,
Could you clarify the output to this program.

ls -l, for example. Are you doing this through the program , or just showing us with the Unix command what the directory contains?

Thanks
Logged
esc
Global Moderator
Full Member
*****
Posts: 230






« Reply #1 on: February 11, 2009, 12:00:40 AM »

"ls -l" shows the content of the directory.  This command is run from a terminal/shell.  On my Mac, I opened a terminal window and ran the book's program 16.6 copy command line program.

Hope this helps.
Logged
mdeh
Full Member
***
Posts: 166






« Reply #2 on: February 11, 2009, 06:30:44 AM »

What do you mean by
Quote
I.......ran the book's program 16.6 copy command line program.

OH...I think I know what you mean. You ran it *from* terminal.
OK...so the next question is ...

Do you have to build the program in Xcode to do this, or is that already done?

And

Where ( in which directory/folder)  is the actual program? ( Is that the so-called executable file?)

thanks
« Last Edit: February 11, 2009, 06:45:28 AM by mdeh » Logged
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #3 on: February 11, 2009, 07:03:35 AM »

Do you have to build the program in Xcode to do this, or is that already done?

You can build it from Xcode as a command line tool or from inside Terminal directly using the gcc command as discussed very early on in the text (page 16)

Cheers,

Steve
Logged
mdeh
Full Member
***
Posts: 166






« Reply #4 on: February 11, 2009, 10:50:10 AM »

Steve..appreciate your answer. I guess what i am still trying to get is whether you can run ls -l **from** within the Xcode debugger (eg console window), for instance, or whether you ran the entire program from say, terminal? I am just trying to emulate your output exactly.
PS..I know this is not excatly Obj-C, but some of us are not exactly up to scratch in Unix commands etc
Thanks
Logged
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #5 on: February 11, 2009, 11:39:17 AM »

You can't run the ls command from inside the Console window.  The ls command is a Unix command, and needs to be run by the Unix shell.  That's why you need a Terminal window (which runs a shell) to do this task.

The entire sequence shown in Program 16.6 Output needs to be run inside a terminal window, not just the ls command--sorry that this was not made clearer in the text.  The purpose of the example is to show how to access the two file names typed as arguments on the command line to perform a copy file operation.


Cheers,

Steve
« Last Edit: February 11, 2009, 11:47:40 AM by skochan » Logged
mdeh
Full Member
***
Posts: 166






« Reply #6 on: February 11, 2009, 11:46:37 AM »

OK...so you called the "copy" from terminal? so, it's just a matter of making sure that the correct path to copy is given.
Thanks


OK>..thanks Steve...your input is appreciated. Very rare for an author to interact with his/her readers like this. As you can see, it is much appreciated by all
« Last Edit: February 11, 2009, 02:23:04 PM by mdeh » Logged
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #7 on: February 11, 2009, 11:48:17 AM »

See my previous reply.  I was editing it when you snuck yours in.  You're too fast for me!   Shocked
Logged
esc
Global Moderator
Full Member
*****
Posts: 230






« Reply #8 on: February 11, 2009, 04:56:28 PM »

mdeh, you asked:
> Where ( in which directory/folder)  is the actual program? ( Is that the so-called executable file?)

I build the book's (sample) programs and the answers to the exercises from Xcode.  Each project is stored in a directory in my home directory.  For example for exercise 1, the project is in
~/Obj-C/chapter16-ex1/

The project's source file called chapter16-ex1.m is in ~/Obj-C/chapter16-ex1/.  Its executable is in
~/Obj-C/chapter16-ex1/build/Debug/
and the executable is called chapter16-ex1.  (If you use the Unix command "ls -F", you will see "chapter16-ex1*")


Logged
mdeh
Full Member
***
Posts: 166






« Reply #9 on: February 11, 2009, 05:12:05 PM »

Thanks for that. I had to laugh as I suddenly realized I had been using Xcode's ability to supply command-line arguments without fully realizing that that is what one is doing in terminal,  with, for example, cp -l file1 file2 etc!!!
Thanks again.
Michael.
Logged
mdeh
Full Member
***
Posts: 166






« Reply #10 on: February 12, 2009, 06:38:54 AM »

You can't run the ls command from inside the Console window.  The ls command is a Unix command, and needs to be run by the Unix shell.  That's why you need a Terminal window (which runs a shell) to do this task.

The entire sequence shown in Program 16.6 Output needs to be run inside a terminal window, not just the ls command--sorry that this was not made clearer in the text.  The purpose of the example is to show how to access the two file names typed as arguments on the command line to perform a copy file operation.

Steve...may I make a small suggestion?
I know this is not a book about Unix, but at some point, users, like myself, will probably want to run some of their programs ( this one for example)  from the terminal. Perhaps a very small diversion ( as a footnote ) about PATHS would be good here. For instance, if one tried to copy your terminology, using just the command "copy" (page 396) it would fail unless you had added the folder to the PATH, or added copy to one of the existing PATHS, neither of which I suspect you would recommend. Is it reasonable to suggest then to navigate to the current folder that contains the executable and use the command ./programName?
Michael.

Michael, check page 18. --SK
« Last Edit: February 12, 2009, 07:18:18 AM by skochan » Logged
mdeh
Full Member
***
Posts: 166






« Reply #11 on: February 12, 2009, 07:21:44 AM »

Embarrassed again!!!
I skipped the stuff about "terminal" as I thought I would never be using it!!!
Thanks
Logged
kh
Newbie
*
Posts: 1






« Reply #12 on: May 20, 2010, 05:18:08 PM »

Thanks for the help in this thread; I'm new to programming and I too was at a loss about how to run 16.6 until Google pointed me here.  I think the command-line-arg nature of 16.6 can really throw newbies for a loop, and though the command line is explained some 300 pages back, it may help to include a Note about how to run this program.

In case it helps others, the gist is:

At least for xcode users, Program 16.6 is not like prior programs in the book. You don't "Build and Run" and see what happens in the console.

You have to run and pass arguments to the executable file generated when you compile the program. Here's what I did:

1. Write, and then build the program, to generate an executable file.
2. Create at least one text file to test. I used "New File" in Xcode, chose "Other -- Empty File" and placed it inside the build/Debug directory. I named it "file1" and entered some sample text into it.
3. Open a Terminal window from OS X.
4. Navigate to the directory where the executable file is stored. For me, that's:
  cd Documents/ObjC\ Progs/prog16-6/build/debug

Inside the debug directory, I see that the executable file generated is named "prog16-6" (since my project name is titled prog16-6).

5. Type "mkdir newdir" (so you can test copying to a new directory).

6. type "./prog16-6 file1 backup1"

This should copy file1 into a new file called backup1, in the same directory.

7. type "./prog16-6 file1 newdir"

This should copy file1 to a new file, also called file1, inside the newdir directory.

After figuring this out, Getting exercise 16-1 working was straightforward too.
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.