2013-05-15 1 views
0

Mac (iOS가 아님) 애플리케이션이 있습니다. 사용자가 NSOpenPanel 폴더를 선택하면 쉘 명령 'find'를 실행하고 싶습니다. 다음은 내가 가지고있는 것입니다.NSTask 파일 경로 ShellPath로 변환 하시겠습니까?

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 응용 프로그램에서 쉘 명령을 실행하는 것은 처음입니다. 나는 옳은 길에 있다고 생각합니다. 어쨌든, 폴더를 선택하면 다음 디버거 출력 메시지가 나타납니다.

  • 발견은 : 커밋 : 없음 같은 파일 또는 디렉터리
  • 찾기 : 찾기 :/볼륨/SDHC 16기가바이트/더 -name '를 ._ *'타입 F : 해당 파일이나 디렉토리

쉘 명령이 이런 종류의 파일 경로를 읽을 수 없다고 가정합니다. 쉘 경로 나 이해할 수있는 경로로 변환해야합니까? 그렇다면 어떻게?

감사합니다.

답변

1

알겠습니다.

NSString *path = [url path]; 
NSString *folderName = [path lastPathComponent]; 

NSTask *task = [[NSTask alloc] init]; 
[task setLaunchPath:@"/usr/bin/find"]; 
NSMutableString *command = [[NSMutableString alloc] initWithString:@""]; 
[command appendString:@" -name '._*' -type f"]; 
NSArray* args = [NSArray arrayWithObjects:path,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);