Re: determine whether an ancillary program/task can run
Re: determine whether an ancillary program/task can run
- Subject: Re: determine whether an ancillary program/task can run
- From: Dave DeLong <email@hidden>
- Date: Thu, 01 Sep 2011 14:12:27 -0700
You could probably catch this before attempting to launch the task. Create a new NSBundle object pointing at the executable path, and then ask the bundle for the -executableArchitectures, and see if one of the returned values matches the architecture of the machine you're running. If it matches, then launch the task. :)
Cheers,
Dave
On Sep 1, 2011, at 2:09 PM, Martin Wierschin wrote:
> Hello all,
>
> My application sometimes need to run an ancillary program (included in the app's resources). I do this via NSTask and normally it works great.
>
> The problem is that this ancillary program is sometimes Intel-only, or sometimes PPC-only, while the main application is Universal. The use of this ancillary program is not mandatory, so displaying an error message, or using a fallback solution is acceptable. The issue is that trying to run an ancillary program on an unsupported architecture triggers a hard crash:
>
>>> Exception Type: EXC_BREAKPOINT (SIGTRAP)
>>> Exception Codes: 0x0000000000000001, 0x000000009030c0b0
>>> Crashed Thread: 0
>>>
>>> Application Specific Information:
>>> *** NSTask: Task create for path '.../Resources/mysubtool' failed: 86, "Bad CPU type in executable". Terminating temporary process.
>>> *** multi-threaded process forked ***
>
>>>
>>> Thread 0 Crashed:
>>> 0 com.apple.Foundation 0x9030c0b0 ___NEW_PROCESS_COULD_NOT_BE_EXECD___ + 0
>>> 1 com.apple.Foundation 0x901d0354 -[NSConcreteTask launchWithDictionary:] + 2472
>
> Is there an elegant way to catch this? I'd rather not try to figure out the arch of the ancillary program, host arch, and (if relevant) whether Rosetta is installed or not.
>
> Thanks,
> ~Martin
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden