Re: Wait for NSTask to finish
Re: Wait for NSTask to finish
- Subject: Re: Wait for NSTask to finish
- From: John Timmer <email@hidden>
- Date: Wed, 16 Mar 2005 19:19:23 -0500
Title: Re: Wait for NSTask to finish
Actually, the termination notification is fine for this. The notification object contains the task, so you can check what the path to that binary was and then figure out what should be next in the process based on a combination of that and your prefs. In practical terms, what I’d do is copy all the prefs over to a “to do” dictionary of booleans where the keys are the paths to the binaries you need to execute - do this at the very start, before launching anything. You can then tick them off to false as you complete them, based on which task has just called in as done. In psuedo-code (complete with annoying Entourage supplied capitalizations), your notification callback should be:
[toDoDictionary setObject: [NSNumber numberWithBool: NO] forKey: [finishedTask launchPath]];
If ( [[toDoDictionary objectForKey: @”binaryPath1”] boolValue] ) {
// launch the task with binaryPath1
return;
}
If ( [[toDoDictionary objectForKey: @”binaryPath2”] boolValue] ) {
// launch the task with binaryPath2
return;
}
If you really need to get fancy in terms of including this to do list in a way that’s picked up in the notification callback, NSTasks have a dictionary of environment variables, and you can stuff any arbitrary objects you want in that. In the past, I’ve loaded the dictionary up with the task arguments and an array of files I needed to process, so that when it completed, I could grab them back out and re-launch a new task with the same arguments and a new file.
JT
I don't think I can use NSTaskDidTerminateNotification as after it's done, the app goes on to run another command, if the user prefs are set to do so. It looks a bit like this.
- (IBAction)executeBatchTasks:(id)sender
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchRPOn"])
{
[task waitUntilExit];
[self rp:nil];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchRCOn"])
{
[task waitUntilExit];
[self rc:nil];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchUPOn"])
{
[task waitUntilExit];
[self up:nil];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchCCOn"])
{
[task waitUntilExit];
[self cuc:nil];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchFETOn"])
{
[task waitUntilExit];
[self fet:nil];
}
}
But, as I said before, the app hangs and the cancel button won't work, etc...
Thanks a lot,
_______________________________________________
This mind intentionally left blank
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden