Re: Launching Cocoa Application externally

2008-05-15 Thread Douglas Davidson


On May 15, 2008, at 11:45 AM, Jens Alfke wrote:

The problem was that I access a file (without proper error- 
handling; I will add that now :-)). The default working directory  
is the main-bundle path when run from within XCode and it is "/"  
when run from Finder.


I repaired this by adding
[[NSFileManager defaultManager] changeCurrentDirectoryPath:
   [[[NSBundle mainBundle] bundlePath]  
stringByDeletingLastPathComponent]];

to my awakeFromNib. I hope this works as I intend.



That will work, although if any other -awakeFromNib method (of an  
object in that nib) wants to use a relative path, you have a race  
condition, because the order in which -awakeFromNib methods are  
called is, basically, random.


But it's better to just avoid using relative paths, if possible. If  
you're accessing a file inside your bundle, you should use the  
NSBundle resource APIs to get its location.


Let me echo what Jens said.  The cwd is for command-line tools; don't  
use it, or anything that relies on it, in an application context, if  
you can do anything to avoid it.


Douglas Davidson

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-15 Thread Jens Alfke


On 15 May '08, at 9:42 AM, Yann Disser wrote:

The problem was that I access a file (without proper error-handling;  
I will add that now :-)). The default working directory is the main- 
bundle path when run from within XCode and it is "/" when run from  
Finder.


I repaired this by adding
[[NSFileManager defaultManager] changeCurrentDirectoryPath:
[[[NSBundle mainBundle] bundlePath]  
stringByDeletingLastPathComponent]];

to my awakeFromNib. I hope this works as I intend.



That will work, although if any other -awakeFromNib method (of an  
object in that nib) wants to use a relative path, you have a race  
condition, because the order in which -awakeFromNib methods are called  
is, basically, random.


But it's better to just avoid using relative paths, if possible. If  
you're accessing a file inside your bundle, you should use the  
NSBundle resource APIs to get its location.


—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Re: Launching Cocoa Application externally

2008-05-15 Thread Sherm Pendley
On Thu, May 15, 2008 at 12:42 PM, Yann Disser <[EMAIL PROTECTED]> wrote:

> Thank you all for your help. I managed to fix the problem by going over
> your suggestions.
>
> The problem was that I access a file (without proper error-handling; I will
> add that now :-)). The default working directory is the main-bundle path
> when run from within XCode and it is "/" when run from Finder.
>
> I repaired this by adding
> [[NSFileManager defaultManager] changeCurrentDirectoryPath:
>[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]];
> to my awakeFromNib. I hope this works as I intend.


You shouldn't rely on the current working directory. Just use the call to
-bundlePath (or one of NSBundles many other methods for finding paths to
different bundle internals) to create a fully-qualified path to the file you
want to open.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-15 Thread Jean-Daniel Dupas


Le 15 mai 08 à 18:42, Yann Disser a écrit :

Thank you all for your help. I managed to fix the problem by going  
over your suggestions.


The problem was that I access a file (without proper error-handling;  
I will add that now :-)). The default working directory is the main- 
bundle path when run from within XCode and it is "/" when run from  
Finder.


I repaired this by adding
[[NSFileManager defaultManager] changeCurrentDirectoryPath:
[[[NSBundle mainBundle] bundlePath]  
stringByDeletingLastPathComponent]];

to my awakeFromNib. I hope this works as I intend.

Yann


I hope your are not trying to access some bundle resources using a  
relative path? To access resources into a bundle you should always use  
NSBundle methods, it will avoid you this kind of problem.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-15 Thread Yann Disser
Thank you all for your help. I managed to fix the problem by going  
over your suggestions.


The problem was that I access a file (without proper error-handling; I  
will add that now :-)). The default working directory is the main- 
bundle path when run from within XCode and it is "/" when run from  
Finder.


I repaired this by adding
[[NSFileManager defaultManager] changeCurrentDirectoryPath:
[[[NSBundle mainBundle] bundlePath]  
stringByDeletingLastPathComponent]];

to my awakeFromNib. I hope this works as I intend.

Yann
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally (Yann Disser)

2008-05-14 Thread Hamish Allan
Please stop copying Yann Disser's name into the subject line! It
breaks up threads unnecessarily.

Hamish
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Launching Cocoa Application externally (Yann Disser)

2008-05-14 Thread Peter Hudson

Here's a few suggestions

a) Check your settings in project   ( as in project -> edit project  
settings )

Check that your target platform and  lib selection is OK.
Ensure that you are not zero linking.

b) Do a completely clean build -  i.e. close the project and drop the  
build directory into the trash.

Do a deployment build.

c) Do you get anything written to the system log from the app  
( before it crashes )  ?


d) If your NSApp has a delegate, try and put an NSLog or two into it  
somewhere and see if they get printed out.



(PH)


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-14 Thread Jean-Daniel Dupas


Le 14 mai 08 à 19:56, Stuart Malin a écrit :



On May 14, 2008, at 5:55 AM, [EMAIL PROTECTED] wrote:


The App runs fine in gdb and even writes the output file.

Still the same error (crash and no output written) when running it
with "open MyApp.app".

Yann


Have you built a deployment (Release) version? Unless you have done  
so, a Debug version will run fine under Xcode, but not standalone  
because of zerolink (possibly among other reasons). Use the  
"Project" menu --> "Set Active Build Configuration" to set this.



Note that zero-link was removed in Xcode 3.0 and no longer exists.

As I said, the crash log will probably help to find what goes wrong.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-14 Thread Stuart Malin


On May 14, 2008, at 5:55 AM, [EMAIL PROTECTED] wrote:


The App runs fine in gdb and even writes the output file.

Still the same error (crash and no output written) when running it
with "open MyApp.app".

Yann


Have you built a deployment (Release) version? Unless you have done  
so, a Debug version will run fine under Xcode, but not standalone  
because of zerolink (possibly among other reasons). Use the "Project"  
menu --> "Set Active Build Configuration" to set this.




On 14. May 2008, at 16:47, Jens Alfke wrote:



On 14 May '08, at 6:48 AM, Yann Disser wrote:


How can I debug my App from Finder (or Terminal) to see where it
crashes? (printf("hallo\n") doesn't work either)


From a shell, enter "gdb MyApp.app", then "run".

I would suspect a dyld error, like a framework/library not found.
The Finder / LaunchServices is really bad at reporting these.
Running the app from a shell or gdb should report more useful info.


On 14 May '08, at 6:55 AM, Stéphane wrote:

There's a bug in your code or in your Info.plist.


Actually I think we could answer almost all of the questions on this
list that way ;-)


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-14 Thread Andy Lee

Is MyApp.app a Release build or a Debug build?

--Andy

On May 14, 2008, at 11:13 AM, Yann Disser wrote:


The App runs fine in gdb and even writes the output file.

Still the same error (crash and no output written) when running it  
with "open MyApp.app".


Yann


On 14. May 2008, at 16:47, Jens Alfke wrote:



On 14 May '08, at 6:48 AM, Yann Disser wrote:

How can I debug my App from Finder (or Terminal) to see where it  
crashes? (printf("hallo\n") doesn't work either)


From a shell, enter "gdb MyApp.app", then "run".

I would suspect a dyld error, like a framework/library not found.  
The Finder / LaunchServices is really bad at reporting these.  
Running the app from a shell or gdb should report more useful info.



On 14 May '08, at 6:55 AM, Stéphane wrote:

There's a bug in your code or in your Info.plist.


Actually I think we could answer almost all of the questions on  
this list that way ;-)


—Jens


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/aglee%40mac.com

This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-14 Thread Yann Disser

The App runs fine in gdb and even writes the output file.

Still the same error (crash and no output written) when running it  
with "open MyApp.app".


Yann


On 14. May 2008, at 16:47, Jens Alfke wrote:



On 14 May '08, at 6:48 AM, Yann Disser wrote:

How can I debug my App from Finder (or Terminal) to see where it  
crashes? (printf("hallo\n") doesn't work either)


From a shell, enter "gdb MyApp.app", then "run".

I would suspect a dyld error, like a framework/library not found.  
The Finder / LaunchServices is really bad at reporting these.  
Running the app from a shell or gdb should report more useful info.



On 14 May '08, at 6:55 AM, Stéphane wrote:

There's a bug in your code or in your Info.plist.


Actually I think we could answer almost all of the questions on this  
list that way ;-)


—Jens


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-14 Thread Jens Alfke


On 14 May '08, at 6:48 AM, Yann Disser wrote:

How can I debug my App from Finder (or Terminal) to see where it  
crashes? (printf("hallo\n") doesn't work either)


From a shell, enter "gdb MyApp.app", then "run".

I would suspect a dyld error, like a framework/library not found. The  
Finder / LaunchServices is really bad at reporting these. Running the  
app from a shell or gdb should report more useful info.



On 14 May '08, at 6:55 AM, Stéphane wrote:

There's a bug in your code or in your Info.plist.


Actually I think we could answer almost all of the questions on this  
list that way ;-)


—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Re: Launching Cocoa Application externally

2008-05-14 Thread Jean-Daniel Dupas
You can read the crash log to see what goes wrong. (/Applications/ 
Utilities/Console.app)



Le 14 mai 08 à 15:48, Yann Disser a écrit :

When I launch my Cocoa application from Finder instead of from  
within XCode, it reports a crash. All my other Projects seem to work  
well from outside XCode...


I tried to debug my App by changing the main-function to

int main(int argc, char *argv[])
{
 [[NSString stringWithString:@"hier"] writeToFile:@"debug.txt"  
atomically:YES];

 exit(0);
   return NSApplicationMain(argc,  (const char **) argv);
}

From within XCode this writes the file "debug.txt". From Finder it  
doesn't. The same behaviour occurs with my other apps.


How can I debug my App from Finder (or Terminal) to see where it  
crashes? (printf("hallo\n") doesn't work either)
Maybe someone has an idea why my App crashes when launches from  
Finder/Terminal and runs perfectly from within XCode?


Thanks,
Yann



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/devlists%40shadowlab.org

This email sent to [EMAIL PROTECTED]



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Launching Cocoa Application externally

2008-05-14 Thread Stéphane


On May 14, 2008, at 3:48 PM, Yann Disser wrote:

When I launch my Cocoa application from Finder instead of from  
within XCode, it reports a crash. All my other Projects seem to  
work well from outside XCode...


I tried to debug my App by changing the main-function to

int main(int argc, char *argv[])
{
  [[NSString stringWithString:@"hier"] writeToFile:@"debug.txt"  
atomically:YES];

  exit(0);
return NSApplicationMain(argc,  (const char **) argv);
}

From within XCode this writes the file "debug.txt". From Finder it  
doesn't. The same behaviour occurs with my other apps.


Where is "debug.txt" supposed to be created according to you?

Maybe someone has an idea why my App crashes when launches from  
Finder/Terminal and runs perfectly from within XCode?


There's a bug in your code or in your Info.plist.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Launching Cocoa Application externally

2008-05-14 Thread Yann Disser
When I launch my Cocoa application from Finder instead of from within  
XCode, it reports a crash. All my other Projects seem to work well  
from outside XCode...


I tried to debug my App by changing the main-function to

int main(int argc, char *argv[])
{
  [[NSString stringWithString:@"hier"] writeToFile:@"debug.txt"  
atomically:YES];

  exit(0);
return NSApplicationMain(argc,  (const char **) argv);
}

From within XCode this writes the file "debug.txt". From Finder it  
doesn't. The same behaviour occurs with my other apps.


How can I debug my App from Finder (or Terminal) to see where it  
crashes? (printf("hallo\n") doesn't work either)
Maybe someone has an idea why my App crashes when launches from Finder/ 
Terminal and runs perfectly from within XCode?


Thanks,
Yann



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]