1996-05-28 18:33:00 +00:00
|
|
|
|
2001-06-21 04:49:20 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
2000-09-22 13:45:58 +00:00
|
|
|
|
2001-06-21 04:49:20 +00:00
|
|
|
@interface TaskMan : NSObject
|
1996-05-28 18:33:00 +00:00
|
|
|
{
|
2001-06-21 04:49:20 +00:00
|
|
|
NSMutableArray *taskList;
|
1996-05-28 18:33:00 +00:00
|
|
|
}
|
2001-06-21 04:49:20 +00:00
|
|
|
|
|
|
|
-nextTask:(NSNotification *) aNotification;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TaskMan
|
|
|
|
-init
|
|
|
|
{
|
|
|
|
NSTask *aTask;
|
|
|
|
|
|
|
|
self = [super init];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(nextTask:)
|
|
|
|
name:NSTaskDidTerminateNotification
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
taskList = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
aTask = [[NSTask alloc] init];
|
|
|
|
[aTask setLaunchPath:@"/bin/ls"];
|
|
|
|
[aTask setArguments:nil];
|
|
|
|
[taskList addObject:aTask];
|
|
|
|
|
|
|
|
aTask = [[NSTask alloc] init];
|
|
|
|
[aTask setLaunchPath:@"/bin/ps"];
|
|
|
|
[aTask setArguments:nil];
|
|
|
|
[taskList addObject:aTask];
|
|
|
|
|
|
|
|
aTask = [[NSTask alloc] init];
|
|
|
|
[aTask setLaunchPath:@"/bin/pwd"];
|
|
|
|
[aTask setArguments:nil];
|
|
|
|
[taskList addObject:aTask];
|
|
|
|
|
|
|
|
aTask = [[NSTask alloc] init];
|
|
|
|
[aTask setLaunchPath:@"/bin/date"];
|
|
|
|
[aTask setArguments:nil];
|
|
|
|
[taskList addObject:aTask];
|
|
|
|
|
|
|
|
[[taskList objectAtIndex:0] launch];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-nextTask:(NSNotification *) aNotification
|
|
|
|
{
|
|
|
|
if ([[aNotification object] terminationStatus] == 0) {
|
|
|
|
[NSNotification notificationWithName:@"CommandCompletedSuccessfully"
|
|
|
|
object:self];
|
|
|
|
} else {
|
|
|
|
[NSNotification notificationWithName:@"CommandFailed"
|
|
|
|
object:self];
|
|
|
|
}
|
|
|
|
[taskList removeObjectAtIndex:0];
|
|
|
|
|
|
|
|
if ([taskList count] > 0)
|
|
|
|
[[taskList objectAtIndex:0] launch];
|
|
|
|
else
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main(int argc, char **argv, char** env)
|
2000-09-20 13:48:49 +00:00
|
|
|
{
|
2001-06-21 04:49:20 +00:00
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
TaskMan *aTaskMan;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
pool = [NSAutoreleasePool new];
|
|
|
|
aTaskMan = [[TaskMan alloc] init];
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
[[NSRunLoop currentRunLoop] runOnceBeforeDate:
|
|
|
|
[NSDate dateWithTimeIntervalSinceNow: 5]];
|
|
|
|
|
|
|
|
/* Uncomment the following line, and the app will complete all tasks */
|
|
|
|
/* otherwise it will hang */
|
|
|
|
//printf("%d\n", i++);
|
|
|
|
// NSLog(@"");
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
2000-09-20 13:48:49 +00:00
|
|
|
}
|
2001-06-21 04:49:20 +00:00
|
|
|
|