开发者

Running multiple NSTasks consecutively

I need to run multiple commands in sequence using NSTask and was wondering what would be a good way to tell if a task has finished so I can continue on to the next command. I'm using "sox" (which I am including in my application bundle) to create temporary audio files using input audio files, and then need to combine those temporary audio files into a single file. An example of the flow of processes (not the actual commands):

1) songA > tempA

2) songB > tempB

3)combine tempA tempB > songC

I'm using the following code to complete the first command:

    NSArray *arguments;
    arguments = [NSArray arrayWithObjects: @"songA", @"-f", @"-S", @"-G", @"-V", @"-b", @"24", @"-r", @"384k", @"tempA", nil];

        NSString *path=[[NSBundle mainBundle] pathForResource:@"sox" ofType:nil];

        NSTask *task;
        task = [[NSTask alloc] init];

        [task setStandardInput:[NSPipe pipe]]; 

        [task setLaunchPath:path];

        [task setArguments: arguments1];

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

        NSFileHandle *file;
        file = [pipe fileHandleForReading];

        [task launch];

        NSData *data;
        data = [file readDataToEndOfFile];

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

 开发者_JS百科       NSLog (@"stuff  :\n%@", string);

        [string release];
        [task release];

Suppposing I needed to perform two more NSTask processes after this one had finished (using the output of the previous processs), what would be the best way to detect that one process has finished so that I can continue on to the next one.

Thanks.


Maybe not understand fully, but

[task waitUntilExit];

does not do the job?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜