NSWorkspace launchApplication:首次以root用户失败 [英] NSWorkspace launchApplication: fails for the first time with root user

查看:181
本文介绍了NSWorkspace launchApplication:首次以root用户失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mac OS X 10.7.4 上从另一个应用程序(例如app1)启动一个应用程序(例如app2).我将以下代码用于同一代码:

I am trying to launch one of my apps(say app2) from another of my apps(say app1) on my Mac OS X 10.7.4. I am using the below code for the same:

[ [ NSWorkspace sharedWorkspace ] launchApplicationAtURL:[NSURL fileURLWithPath:appPath] options:NSWorkspaceLaunchDefault configuration:[NSDictionary dictionaryWithObject:[NSArray arrayWithObject: @"mode"] forKey:NSWorkspaceLaunchConfigurationArguments] error:&err];

除了第一次(即如果我们有一台新机器)之外,此方法都可以正常工作,那么当以root用户身份登录时首次尝试从app1启动app2的第一次尝试失败,但是随后工作正常.

This works fine except for the first time i.e. if we have a new machine, then the first attempt for launching the app2 from app1 fails when tried for the first time when logged in as root user but works fine subsequently.

以下是我在转储NSError时遇到的错误:

Below is the error I get on dumping the NSError:

2012-11-05 07:47:48 +0000:由于发生了其他错误(OSStatus -10810),因此无法启动应用程序"App2".

2012-11-05 07:47:48 +0000: The application "App2" could not be launched because a miscellaneous error occurred (OSStatus -10810).

此外,我在"所有消息"中获得了以下消息在控制台中:

Also, I get the below messages in "All Messages" in Console:

11/4/12 11:47:48.329 PM com.apple.launchd [1]:系统:错误:12B19:启动+ 79534 [AEF41441-17BC-36E6-B1F8-57BADBDFEBCF]:0x0

11/4/12 11:47:48.329 PM com.apple.launchd[1]: System: Bug: 12B19: launchd + 79534 [AEF41441-17BC-36E6-B1F8-57BADBDFEBCF]: 0x0

12年1月4日11:47:48.329 com.apple.launchd [1]:系统:此API仅可用于在Aqua会话中运行的进程.

11/4/12 11:47:48.329 PM com.apple.launchd[1]: System: This API can only be used by a process running within an Aqua session.

11/4/12 11:47:48.329 PM App1 [2405]:spawn_via_launchd()失败,errno = 5标签= [0x0-0x57057] .com.ak.app1路径=/var/root/Library/Caches/com.ak.app2/app2.app/Contents/MacOS/app2标志= 0

11/4/12 11:47:48.329 PM App1[2405]: spawn_via_launchd() failed, errno=5 label=[0x0-0x57057].com.ak.app1 path=/var/root/Library/Caches/com.ak.app2/app2.app/Contents/MacOS/app2 flags=0

一个奇怪的想法是,它只会在root用户首次尝试时失败.

The strange think is that it only fails for the first attempt with root user.

推荐答案

您似乎正在尝试从非UI进程启动应用程序.不再支持此功能,因为它在内部使用LSOpenApplication,自Lion开始不支持非UI进程.有关更多信息,请参见讨论

You appear to be attempting to launch an application from a non-UI process. This is no longer supported, as it uses LSOpenApplication internally, which does not support non-UI processes since Lion. Please see this discussion for more info

这篇关于NSWorkspace launchApplication:首次以root用户失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆