Re: FW: How to change path where Cocoa App is runnin?
Re: FW: How to change path where Cocoa App is runnin?
- Subject: Re: FW: How to change path where Cocoa App is runnin?
- From: Andy Lee <email@hidden>
- Date: Mon, 25 Mar 2002 17:18:24 -0500
Alberto, it looks like Ondra and Jim have just given you the
information you need, but I think they're assuming you know more than
you do. Please don't take offense if I'm wrong about this, but it
sounds like you are new to C programming and possibly Unix concepts.
So in case the answer is still not clear, let me try to break it down
for you.
At 6:02 PM -0300 3/25/02, Alberto wrote:
I have an UNIX app located in path "/Library/Eref/", and a Cocoa app that is
simply a GUI for the UNIX app.
My Cocoa app can be located in any path... but it must be running in
"/Library/Eref/, where are binaries for my UNIX app.
Why?
Because the UNIX app has some config files, that are located in the same
path that binaries.
But as default Cocoa app runs in "/", and this make UNIX app think it's
running from "/", not from "/Library/Eref/".
So.. how to change path "where Cocoa app runs" ?
You cannot change where the Cocoa app defaults to when it launches.
This will always be "/". Trying to change this is not the answer.
Do you understand the concept of "cwd" (Current Working Directory)?
This is very important. At any time during a program's execution, it
is "in" a particular directory location called the current working
directory. This location *can change* throughout the execution of
the program. So although your Cocoa app *starts* with a cwd of "/",
there are ways to make the Unix app it calls run in "/Library/Eref/"
(or whatever you want).
One way, which Ondra suggested, is to use NSFileManager's
-changeCurrentDirectoryPath: method before you launch the Unix app,
like this:
[[NSFileManager defaultManager]
changeCurrentDirectoryPath:@"/Library/Eref/"];
// ...NOW launch the Unix app...
This will change the Cocoa app's working directory from whatever it
was (presumably "/") to "/Library/Eref/". When the Cocoa app
launches the Unix app, the Unix app will have the same working
directory as the Cocoa app had *at that time*.
Another way, which Jim suggested, assumes you are using an instance
of NSTask to launch the Unix app. If this is the case, you can use
NSTask's -setCurrentDirectoryPath: method, like this:
[myTask setCurrentDirectoryPath:@"/Library/Eref/"];
// ...NOW launch the Unix app using myTask...
If you try either (or both) of these approaches and still don't get
the result you want, there is a deeper problem.
I tried argv[0], but did not work.
I saw the code you posted using argv[0]. It tells me you are new to
C. Fortunately, for the immediate purposes of your Cocoa app, argc
and argv are irrelevant. However, I recommend you take some time
when you can to learn the meaning of the main() function and the
arguments passed to it, as well as how C declarations work. You
*must* understand the C language to program effectively in
Objective-C. You must also understand concepts like the cwd. In
general, as a programmer you must understand what every line of code
you type *does*. Otherwise, you are just typing in uninformed
guesses, which is a waste of your time, not to mention frustrating.
People will also respond more positively when you ask for help if you
demonstrate knowledge of the fundamentals that lead up to your
question.
--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.