Objective c 终端OSX:;“字符串”;命令需要命令行开发人员工具

Objective c 终端OSX:;“字符串”;命令需要命令行开发人员工具,objective-c,terminal,Objective C,Terminal,我需要从objective-c 为了实现它,我从obj-c运行一个terminal命令并解析其输出 命令 ioreg -lw0 | grep "EDID" | sed "/[^<]*</s///" | xxd -p -r | strings -6 -(NSString*)runCommand:(NSString*)commandToRun; { NSString *output=@""; @autoreleasepool { NSTask *task;

我需要从
objective-c

为了实现它,我从
obj-c
运行一个terminal命令并解析其输出

命令

ioreg -lw0 | grep "EDID" | sed "/[^<]*</s///" | xxd -p -r | strings -6
-(NSString*)runCommand:(NSString*)commandToRun;
{
    NSString *output=@"";

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

    NSArray *arguments = [NSArray arrayWithObjects:
                          @"-c" ,
                          [NSString stringWithFormat:@"%@", commandToRun],
                          nil];
    NSLog(@"run command: %@",commandToRun);
    [task setArguments: arguments];

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

    NSPipe *errorPipe = [NSPipe pipe];
    [task setStandardError:errorPipe];

    NSFileHandle *file;
    file = [pipe fileHandleForReading];

    NSFileHandle *errorFile;
    errorFile = [errorPipe fileHandleForReading];

    [task launch];

    NSData *data;
    data = [file readDataToEndOfFile];

    NSData* errorData;
    errorData = [errorFile readDataToEndOfFile];


    output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

    NSString *errorOutput;
    errorOutput = [[NSString alloc] initWithData: errorData encoding: NSUTF8StringEncoding];

    }

    return output;
}
我正在使用下面给出的代码执行终端命令

ioreg -lw0 | grep "EDID" | sed "/[^<]*</s///" | xxd -p -r | strings -6
-(NSString*)runCommand:(NSString*)commandToRun;
{
    NSString *output=@"";

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

    NSArray *arguments = [NSArray arrayWithObjects:
                          @"-c" ,
                          [NSString stringWithFormat:@"%@", commandToRun],
                          nil];
    NSLog(@"run command: %@",commandToRun);
    [task setArguments: arguments];

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

    NSPipe *errorPipe = [NSPipe pipe];
    [task setStandardError:errorPipe];

    NSFileHandle *file;
    file = [pipe fileHandleForReading];

    NSFileHandle *errorFile;
    errorFile = [errorPipe fileHandleForReading];

    [task launch];

    NSData *data;
    data = [file readDataToEndOfFile];

    NSData* errorData;
    errorData = [errorFile readDataToEndOfFile];


    output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

    NSString *errorOutput;
    errorOutput = [[NSString alloc] initWithData: errorData encoding: NSUTF8StringEncoding];

    }

    return output;
}
请建议一些类似命令的替代方法或任何解决方法


非常感谢您的关注。

您真的不能,最好的选择是使用
ioreg-lw0 | grep“EDID”| sed/[^
用字符串在本地过滤它-6
您能详细说明@daredevilh您是如何将上述命令发送到远程计算机的吗?实际上,我已经创建了一个应用程序(问题中提供的代码)。用户正在mac笔记本上运行应用程序,应用程序正在捕获他们的系统信息。然后,您应该运行
ioreg-lw0 | grep“EDID”| sed“/[^我按照你说的做了,但是当我运行
strings-6~/Desktop/report.txt
终端再次显示提示并说
xcode选择:注意:在“/Applications/xcode.app”中找不到开发人员工具,请求安装。请在对话框中选择一个选项下载命令行开发人员工具。