您的位置:首页 > 移动开发 > Objective-C

Objective-C 调用sell脚本含参数

2016-06-30 10:31 453 查看
直接可以执行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];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 脚本 objective-c shell