Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
July 23, 2018, 12:54:22 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: terminal help - prog 16.6  (Read 2140 times)
webwrx
Newbie
*
Posts: 41


« on: October 18, 2009, 05:08:29 PM »

I come from a background of DOS and Windows but I have enough UNIX experience to get around the terminal window okay.

I'm having some trouble getting 16.6 to execute in the teriminal window. I named my project 'prog16-6' (yes... I should have just called it copy)... but here's what is happening. It's probably something really simple I've overlooked.

Here's my Debug directory, and then a list of the contents showing prog16-6

Code: (Objective-C)
ben-johnsons-imac:Debug bj2$ pwd
/Users/bj2/Documents/Coding/OBJC2/prog16-6/build/Debug
ben-johnsons-imac:Debug bj2$ ls -l
total 40
-rwxr-xr-x  1 bj2  staff  17168 19 Oct 10:52 prog16-6
ben-johnsons-imac:Debug bj2$

If I try to execute prog16-6 I should get 'Usage: prog16-6 src dest' but instead I get -

Code: (Objective-C)
ben-johnsons-imac:Debug bj2$ prog16-6
-bash: prog16-6: command not found
ben-johnsons-imac:Debug bj2$

With some experimenting, I found that I can execute the program if I run the full path like this -

Code: (Objective-C)
ben-johnsons-imac:Debug bj2$ /Users/bj2/Documents/Coding/OBJC2/prog16-6/build/Debug/prog16-6
2009-10-19 11:04:29.392 prog16-6[9160:10b] Usage: prog16-6 src dest
ben-johnsons-imac:Debug bj2$

Also works if I do this...

Code: (Objective-C)
ben-johnsons-imac:Debug bj2$ ./prog16-6
2009-10-19 11:05:00.937 prog16-6[9165:10b] Usage: prog16-6 src dest
ben-johnsons-imac:Debug bj2$

But not plain old this...

Code: (Objective-C)
ben-johnsons-imac:Debug bj2$ prog16-6
-bash: prog16-6: command not found
ben-johnsons-imac:Debug bj2$

I'm probably going to kick myself when I find out what's going on. Any ideas? It's my understand that ./ refers to the current directory, so why am I having these troubles? Is there a configuration thing I need to set somewhere?

Thanks,
Ben
Logged
rgronlie
Global Moderator
Full Member
*****
Posts: 212



« Reply #1 on: October 19, 2009, 12:54:03 AM »

I'm not sure about other UNIX implementations but OSX will only look in directories specified in it's PATH environment variable for executables.

So in order to run an executable that is not in a directory in PATH you need to explicitly tell OSX where the executable is.

That is why ./prog16-6 worked. You told it to look inside the current directory for the executable.

http://classroomm.com/objective-c/index.php?topic=1578.msg4312#msg4312

Ryan
Logged

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


« Reply #2 on: October 19, 2009, 05:32:12 PM »

I'm not sure about other UNIX implementations but OSX will only look in directories specified in it's PATH environment variable for executables.

So in order to run an executable that is not in a directory in PATH you need to explicitly tell OSX where the executable is.

That is why ./prog16-6 worked. You told it to look inside the current directory for the executable.

http://classroomm.com/objective-c/index.php?topic=1578.msg4312#msg4312

Ryan

Ryan, that makes sense - and thanks for the headsup to the other thread. Coming from a DOS background it seems bizarre that it requires ./ to run a program in the current directory but I'm sure there is a good reason.
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #3 on: October 19, 2009, 06:31:12 PM »

The reason has to do with security.  If the current directory is used (and even worse, if it's searched first), someone can put a Trojan horse into a directory they can write into (e.g. a temp directory).  Then when you make that your current directory and think you're executing a system command, you will run the bogus command in the current directory instead, which can wreak all sorts of havoc.

Cheers,

Steve Kochan
« Last Edit: October 19, 2009, 06:38:52 PM by skochan » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

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 ゥ 2009 classroomM.com. All rights reserved.