gpt4 book ai didi

objective-c - NSTask 不适用于旧版本的 Mac OSX

转载 作者:行者123 更新时间:2023-12-03 16:46:52 25 4
gpt4 key购买 nike

我对包含 NSTask 的方法有一个非常奇怪的问题。在 10.7+ 中,该功能工作得非常好并成功执行,返回结果并将文件复制到所需的目录。

在 10.6.8 中尝试我的应用程序时,NSTask 似乎根本没有执行任何操作,实际上没有错误,也没有任何提示我为什么它不起作用。我尝试了所有可能的角度来确定问题出在哪里,但我已经排除了所有可能性。 :-/

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/sh"];

NSArray *arguments = [NSArray arrayWithObjects: @"-c",
@"find /Data/*.jug/files/ -name thefile | head -n 1 | awk -v dir=\"$HOME/path/to/copy/to\" '{printf \"cp \\\"%s\\\" \\\"%s\\\"\\n\", $1, dir }' | sh", nil];

[task setArguments: arguments];

NSPipe *thePipe = [NSPipe pipe];
[task setStandardInput:[NSPipe pipe]];
[task setStandardOutput:thePipe];

[task launch];
[task waitUntilExit];
[task release];

如果在 10.6.8 中通过终端尝试该命令,我会得到我希望在我的应用程序中得到的结果。我在这里完全不知所措,真的希望有人能够阐明这个问题以及如何解决它。

最佳答案

尝试使用引号,例如:

'/Data/*.jug/files/' 

 \"/Data/*.jug/files/\"

关于objective-c - NSTask 不适用于旧版本的 Mac OSX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14115216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com