【发布时间】:2013-05-15 02:30:30
【问题描述】:
我有一个 Mac(不是 iOS)应用程序。我想在用户使用 NSOpenPanel 选择文件夹后运行 shell 命令“查找”。以下是我所拥有的。
NSString *path = [url path];
NSString *folderName = [path lastPathComponent];
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/find"];
NSMutableString *command = [[NSMutableString alloc] initWithString:path];
[command appendString:@" -name '._*' -type f "];
NSArray* args = [NSArray arrayWithObjects:@"commit",command,nil];
[task setArguments:args];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
[task launch];
NSFileHandle *file;
file = [pipe fileHandleForReading];
NSData *data;
data = [file readDataToEndOfFile];
NSString *output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"%@",output);
这是我第一次在使用 Objective-C 开发的 Mac 应用程序上运行 shell 命令。我想我走在正确的轨道上。无论如何,当我选择一个文件夹时,我会收到以下调试器输出消息。
- 查找:提交:没有这样的文件或目录
- find: find: /Volumes/SDHC 16 GB/More -name '._*' -type f : 没有这样的文件或目录
我认为 shell 命令无法读取这种文件路径。我是否需要将其转换为 shell 路径或它理解的任何内容?如果有,怎么做?
感谢您的建议。
【问题讨论】:
标签: objective-c macos shell osx-mountain-lion nstask