【问题标题】:Results of NSTask in NSTextViewNSTextView 中 NSTask 的结果
【发布时间】:2014-01-25 15:08:55
【问题描述】:

感谢您的帮助。我下面的代码有效,在控制台中返回结果。我想在 textView 中显示相同的结果。无法让它工作。谁能解释我需要做什么?

谢谢。

-(IBAction)activateTask:(id)sender

{

NSURL *fileURL = [NSURL fileURLWithPath:sourceField.stringValue];
NSString *filePath= [fileURL path];

[soxTask setArguments:[NSArray arrayWithObjects:@"--show-progress", filePath, @"-n", @"stats" , nil]];
NSPipe *pipe;
pipe = [NSPipe pipe];
[soxTask setStandardOutput: pipe];

NSFileHandle *file;
file = [pipe fileHandleForReading];


[soxTask launch];
[soxTask waitUntilExit];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData: data
                               encoding: NSUTF8StringEncoding];

[textView setString:string];


///



}

【问题讨论】:

    标签: cocoa nstextview nstask


    【解决方案1】:

    尝试使用 -setStandardError: 代替 -setStandardOutput:

    【讨论】:

      猜你喜欢
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多