NSTask 启动导致崩溃
我有一个可以通过此终端命令导入 XML 文件的应用程序:
打开/path/to/main\ app.app --args myXML.xml
这工作得很好,没有任何问题。我已经使用 Applescript 通过 shell 启动这个命令,它的效果也很好。然而,当尝试使用 Cocoa 的 NSTask Launcher 使用此代码时:
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/open"];
[task setCurrentDirectoryPath:@"/Applications/MainApp/InstallData/App/"];
[task setArguments:[NSArray arrayWithObjects:[(NSURL *)foundApplicationURL path], @"--args", @"ImportP.xml", nil]];
[task launch];
应用程序将启动到初始屏幕,然后在单击下一个按钮或尝试关闭窗口时崩溃。我尝试过使用 NSAppleScript 来执行此操作:
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"tell application \"Terminal\" do script \"open /Applications/MainApp/InstallData/App/Main\\\\ App.app\" end tell"];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
这将启动程序,它也会崩溃,并且我在 Xcode 调试窗口中收到此错误:
12011-01-04 17:41:28.296 LaunchAppFile[4453:a0f]
Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.
Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
LaunchAppFile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
所以通过研究,我想出了这个:
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"do shell script \"arch -i386 osascript /Applications/MainApp/InstallData/App/test.scpt\""];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
但这会导致与最后一个命令相同的结果。 关于导致这次崩溃的原因有什么想法吗?
I have an application that can import an XML file through this terminal command :
open /path/to/main\ app.app --args myXML.xml
This works great with no issues. And i have used Applescript to launch this command through shell and it works just as well. Yet when try using Cocoa's NSTask Launcher using this code :
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/open"];
[task setCurrentDirectoryPath:@"/Applications/MainApp/InstallData/App/"];
[task setArguments:[NSArray arrayWithObjects:[(NSURL *)foundApplicationURL path], @"--args", @"ImportP.xml", nil]];
[task launch];
the applications will start up to the initial screen and then crash when either the next button is clicked or when trying to close the window. Ive tried using NSAppleScript with this :
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"tell application \"Terminal\" do script \"open /Applications/MainApp/InstallData/App/Main\\\\ App.app\" end tell"];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
This will launch the program and it will crash as well and i get this error in my Xcode debug window :
12011-01-04 17:41:28.296 LaunchAppFile[4453:a0f]
Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.
Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
LaunchAppFile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
So with research i came up with this :
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"do shell script \"arch -i386 osascript /Applications/MainApp/InstallData/App/test.scpt\""];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
But this causes the same results as the last command.
Any ideas on what causes this crash?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查此处以修复 adobe 错误。但我不确定这就是问题所在。实际上我无法获得 open 命令来将参数传递给任何东西,所以我无法调查你的问题。
Check here to fix the adobe errors. I'm not sure that's the problem though. Actually I couldn't get the open command to pass arguments to anything so I couldn't look into your problem.
仅使用完整路径再次尝试 NSTask:
另一种方法是为 NSTask 提供以下命令行:
Give NSTask another try with full paths only:
Another approach would be to give NSTask the following command line: