直接可以执行shell脚本,并检查脚本的运行情况
@interface ViewController()
{
NSTimer * timer;
NSTask *task;
}
-(void)shellScript:(NSString *)shellName
{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSSystemDomainMask, YES);
NSString* thepath = [paths lastObject];
NSString * strr = [NSString stringWithFormat:@"%@/%@",thepath,shellName];
task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:[NSArray arrayWithObjects:strr,parameter1,parameter2,nil]];//sh test.sh parameter1 parameter2
[task launch];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
}
-(void)updateTime
{
if (!task.running) {
[timer invalidate];
}
}