尝试运行 NSTask 但出现错误
我有一个独立(第 3 方)应用程序,我试图使用命令“kick”启动它。我已经设置了 ~/.bash_profile 和 /etc/bashrc 文件,以便我可以在终端窗口中输入 kick [command] 并且它可以完美运行。所以我假设我已经正确设置了所有内容。
当我尝试使用 NSTask 时,问题就出现了。
本质上我正在做的是创建两个可变数组,kickBuild 和kickOut。一个用于汇编命令(它是一串标志),另一个用于 NSTask。我将 kickBuild 转换为以空格分隔的字符串,然后将其作为对象添加到第二个数组中。
所以我的命令应该类似于 "kick -i /path/to/input/file.ext -as 2 -g 2.2" 等。如果我将其输入到终端窗口中,效果会很好。
kickBuild = [[NSMutableArray alloc] initWithCapacity:100];
kickOut = [[NSMutableArray alloc] initWithCapacity:2]; // Thinking that this should be "kick" and then "-i /path/to/input/file.ext -as 2 -g 2.2"
kickPath = [kickLocationTextField stringValue]; // This is just the path to my kick executable. NOT /bin/sh. Is that correct?
NSString *tempKick = [kickBuild componentsJoinedByString: @" "];
[kickOut addObject:tempKick];
[NSTask launchedTaskWithLaunchPath:kickPath arguments:kickOut];
当我构建应用程序并运行此代码时,出现此错误...
dyld:未加载库:build/darwin_x86_64/gcc_opt_dynamic/core/libai.dylib
引用自:/Users/Gene/ Kick/Kick-3.3.4.0/bin/kick
原因:找不到图片
这是一个 kickOut 的 NSLog... kick -i /Users/Gene/Test_Main.0001.ext -r 960 540 -as 2 -g 2.2 -v 5 -dp
这是我做错的事情吗?或者这是踢球的问题?
如何使用一些基本终端任务测试 NSTask 以确保我正确使用 NSTask?
kickBuild = [[NSMutableArray alloc] initWithCapacity:5];
kickOut = [[NSMutableArray alloc] initWithCapacity:2];
kickPath = @"/bin/sh";
[kickBuild addObject:@"-c"]; // Do I need this?
[kickBuild addObject:@"ls"];
[kickBuild addObject:@"~/Desktop"];
NSString *tempKick = [kickBuild componentsJoinedByString: @" "];
[kickOut addObject:tempKick];
[NSTask launchedTaskWithLaunchPath:kickPath arguments:kickOut];
如果我在没有@“-c”的情况下运行此命令,我会得到: /bin/sh: ls ~/Desktop: No such file or directory
感谢任何帮助。
感谢一百万
I have a standalone (3rd party) app that I'm trying to launch using a command "kick". I've setup my ~/.bash_profile and /etc/bashrc files so that I can type kick [command] into a terminal window and it works perfectly. So I'm assuming that I have everything setup correctly.
The problem comes when I try and use NSTask.
Essentially what I'm doing is creating two mutable arrays, kickBuild and kickOut. One to assemble the command (it's a string of flags) and one to use with NSTask. I take kickBuild and convert it to a string separated by spaces, then add that as an object into the second array.
So my command should look something like "kick -i /path/to/input/file.ext -as 2 -g 2.2" etc. And if I type this into a terminal window it works great.
kickBuild = [[NSMutableArray alloc] initWithCapacity:100];
kickOut = [[NSMutableArray alloc] initWithCapacity:2]; // Thinking that this should be "kick" and then "-i /path/to/input/file.ext -as 2 -g 2.2"
kickPath = [kickLocationTextField stringValue]; // This is just the path to my kick executable. NOT /bin/sh. Is that correct?
NSString *tempKick = [kickBuild componentsJoinedByString: @" "];
[kickOut addObject:tempKick];
[NSTask launchedTaskWithLaunchPath:kickPath arguments:kickOut];
When I build my app and run this code, I get this error…
dyld: Library not loaded: build/darwin_x86_64/gcc_opt_dynamic/core/libai.dylib
Referenced from: /Users/Gene/Kick/Kick-3.3.4.0/bin/kick
Reason: image not found
This is an NSLog of kickOut…
kick -i /Users/Gene/Test_Main.0001.ext -r 960 540 -as 2 -g 2.2 -v 5 -dp
Is this something that I'm doing wrong? Or is this an issue with kick?
How would I test NSTask with some basic terminal task to make sure that I'm using NSTask correctly?
kickBuild = [[NSMutableArray alloc] initWithCapacity:5];
kickOut = [[NSMutableArray alloc] initWithCapacity:2];
kickPath = @"/bin/sh";
[kickBuild addObject:@"-c"]; // Do I need this?
[kickBuild addObject:@"ls"];
[kickBuild addObject:@"~/Desktop"];
NSString *tempKick = [kickBuild componentsJoinedByString: @" "];
[kickOut addObject:tempKick];
[NSTask launchedTaskWithLaunchPath:kickPath arguments:kickOut];
If I run this without the @"-c", I get: /bin/sh: ls ~/Desktop: No such file or directory
Any help is appreciated.
Thanks a million
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个应该适合您的简单 NSTask 测试(注意:arguments:(NSArray *)arguments):
Here's a simple NSTask test that should work for you (note: arguments:(NSArray *)arguments):
执行 NSTask 时不会读取您的环境设置。
几年前我问过这个问题。
Your environment settings are not read when executing NSTask.
I asked this question a couple of years ago.