0

谢谢您的帮助。这个执行命令的结果显示在我的 Xcode 控制台中。让命令结果显示在 NSTextView 中的最佳方法是什么?

NSString *commandToRun = @"~/Library/webREF/ffmpeg -nostats -i ~/Desktop/input.wav -  filter_complex ebur128 -f null -";



    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];

    NSFileHandle *file;
    file = [pipe fileHandleForReading];

    [task launch];
4

1 回答 1

0

添加类似:

…
NSFileHandle *file;
file = [pipe fileHandleForReading];
NSMutableData *data = [[NSMutableData alloc] init];
NSData *inData = nil;
[task setStandardOutput:pipe];
[task launch];
[task waitUntilExit];

while ((inData = [file availableData]) && [inData length]) {
    [data appendData:inData];
}

[file closeFile];
[task release];
[pipe release];

NSString *result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
[data release];

// somewhere we have an NSTextView textView
[textView setString: result];
于 2013-02-21T21:50:33.390 回答