Objective-C 调用sell脚本含参数

来源:互联网 发布:拓普康数据转换软件 编辑:程序博客网 时间:2024/06/08 19:29

直接可以执行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];    }}


1 0
原创粉丝点击