我正在尝试使NSTask运行这样的命令:
ps -clx | grep'Finder'| awk'{print $ 2}'
这是我的方法
- (void) processByName:(NSString*)name {
NSTask *task1 = [[NSTask alloc] init];
NSPipe *pipe1 = [NSPipe pipe];
[task1 waitUntilExit];
[task1 setLaunchPath: @"/bin/ps"];
[task1 setArguments: [NSArray arrayWithObjects: @"-clx", nil]];
[task1 setStandardOutput: pipe1];
NSTask *task2 = [[NSTask alloc] init];
NSPipe *pipe2 = [NSPipe pipe];
[task2 setLaunchPath: @"/usr/bin/grep"];
[task2 setArguments: [NSArray arrayWithObjects: @"'Finder'", nil]];
[task2 setStandardInput:pipe1];
[task2 setStandardOutput: pipe2];
NSTask *task3 = [[NSTask alloc] init];
NSPipe *pipe3 = [NSPipe pipe];
[task3 setLaunchPath: @"/usr/bin/grep"];
[task3 setArguments: [NSArray …Run Code Online (Sandbox Code Playgroud)