I'm new in all these and I would like to excuse me for my ignorance..
I have a unix executable file. I run through terminal with command: open programname --args argument and it responds that can't find the resource file(which is the argument that I'v passed.)
I tried by writing: ./programname argument and it works.
Firstly, I would like to know the difference between these two methods and why the first one doesn't work, while the second works.
The problem that I have now is that I can't do it in XCode. When a executable is running, it says that it can't 开发者_如何转开发find the resourse file. I passed an argument in executable by cmd+i to executable and adding the resource file as an argument.
Thank you for your potential answer..
open
is the exact equivalent of double clicking on a thing in the Finder. So if you use it on a UNIX executable then the executable will launch but the current working directory won't be where the executable is located and won't necessarily be anything useful. However, you could also use it to open a .doc file or any other file type, to open a directory in the Finder, to open a URL in the finder, etc.
Launching an executable with ./name is a normal UNIX way to run the thing. The current working directory will be wherever you are when you type it. So that'll be the same directory as the executable is located in (unless you launch from elsewhere on the disk, e.g. by going down a directory and using ../name to launch the executable).
What you probably want to do is write code to get the path to the executable, and seek the specified file relative to that? You don't say what language you're working in, and annoyingly that's not something that's in the POSIX spec so it varies from OS to OS.
If you're in C or anything that can call C (so, C++, Objective-C, etc) then NSGetExecutablePath
(ignore Google's desire to put an underscore before it, see e.g. this site) is quite probably what you want. If you're in Objective-C then NSString
has some methods for automatically appending paths.
"open" is a command that works exactly as if you had navigated to a specific application via Finder and then double-clicked it.
./ is a way of running a particular file that's marked executable via chmod.
For example, you can run a Mac OS X application from the command line by entering "open /Applications/MyApp.app/". But it won't work if you do ./MyApp.app/ (assuming you're in the /Applications directory).
If you type "man open" into your terminal, you can read more details there.
精彩评论