繁体   English   中英

从iPhone stderr定期读取

[英]periodic read from iPhone stderr

我正在为自己的调试目的使用一个类。 我打算将其作为调试器控制台的设备版本。 我主要关心捕获NSLog()语句。 无论我登录到控制台什么,我都只能从fgetc()获得0xFF。 我希望从fgetc()看到的是自上次调用update以来发送给stderr的字符。 下面是UITextView的子类:

在标头stdErrFP定义为: FILE* stdErrFP;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
       stdErrFP = fdopen (fileno (stderr) , "w");
       if (!stdErrFP)
           NSLog(@"errno - %s", strerror(errno));

       [self update];
       [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(makeSomeNoise) userInfo:nil repeats:YES];
       [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(update) userInfo:nil repeats:YES];
    }
    return self;
}

-(void) update{
 char errBuff[2] = {0x00, '\0'};
 do{
  errBuff[0] = fgetc(stdErrFP);
  self.text = [NSString stringWithFormat:@"%@%@", self.text,  [NSString stringWithCString:errBuff]];
 }while (errBuff[0] != EOF); 
}

-(void) makeSomeNoise{
 CFShow([NSString stringWithString:@"noisy CFFunction"]);
 NSLog(@"noisy NSLog");
 char message[] = "noisy fprintf";
 fprintf(stderr, message);
}

-(void)makeSomeNoise有很多不同的日志类型,因为Eric Sadun写道NSLog不会记录到stderr ,因此我想排除这种可能性。 我不确定这是否与我的问题有关,但我注意到fdopen()总是失败,除非标志为“ w”,这是不对的。

更新:对于fdopen()我错了,不仅不是只有“ w”有效,而是只有“ r”不起作用。 (即“ a”和“ w”均起作用)。 我使用“ r”时的错误号是: No such file or directory 因此,看来我没有正确连接到stderr。 StackOverflow Genius,请帮忙。

尽我所能编码,您无法从stderr阅读。 stderr缓冲区就像firehose,试图获取有意义的任何东西都非常依赖时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM