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

时间:2016-03-21 11:04:41

标签: objective-c terminal

我需要从objective-c

获取屏幕/显示器的制造商

为了实现它,我正在运行obj-c的终端命令并解析其输出。

命令

ioreg -lw0 | grep "EDID" | sed "/[^<]*</s///" | xxd -p -r | strings -6

它在我的系统上工作正常但是当我从我的代码或用户系统上的Terminal运行相同的命令时,它会显示一个提示,要求我下载一些不可用的开发人员工具我要在所有用户的系统上做。

提示的屏幕截图:

enter image description here

终端上的命令结果

n:~ user$ ioreg -lw0 | grep "EDID" | sed "/[^<]*</s///" | xxd -p -r | strings -6 
P .00 6 LP133WX3-TLA3 Color LCD n:~ user$

我使用下面给出的代码执行终端命令

-(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;
}

请提供类似命令的替代方法或任何解决方法。

非常感谢你的关注。

1 个答案:

答案 0 :(得分:1)

你不能真的,最好的选择是使用ioreg -lw0 | grep "EDID" | sed "/[^<]*</s///" | xxd -p -r将其发送到你的主mac,然后用strings -6在本地过滤。

编辑:在评论中您的详细信息后,您应该: 在他们的Mac上运行ioreg -lw0 | grep "EDID" | sed "/[^<]*</s///" | xxd -p -r > ~/Desktop/report.txt告诉他们发送你的文件。假设您在桌面上收到了它,然后在本地计算机上运行strings -6 ~/Desktop/report.txt

相关问题