Objective-C 调用sell脚本含参数
2016-06-30 10:31
453 查看
直接可以执行shell脚本,并检查脚本的运行情况
-(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];
}
}
@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];
}
}
相关文章推荐
- android wifi 无线调试
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 运维入门
- 动态清空 nohup 输出文件
- install scrapy with pip and easy_install
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- Linux Shell常用技巧
- Shell 脚本编程陷阱
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- VBS脚本写的Windows硬件检测工具分享
- 用vbscript实现隐藏任务栏图标的脚本
- 用autoit编写第一个脚本(Hello World)
- VBS调用WMI快速关闭IE的脚本
- Oracle数据库执行脚本常用命令小结
- 收集的ROS防火墙脚本