Question

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

        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.

Was it helpful?

Solution

Maybe not understand fully, but

[task waitUntilExit];

does not do the job?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top