复制+ (NSString *)run_Shell:(NSString *)shell_path {
if(shell_path) {
NSTask *script_task = [[NSTask alloc] init];
NSPipe *pipe = [NSPipe pipe];
[script_task setStandardOutput:pipe];
[script_task setStandardError:pipe];
NSFileHandle *file_handle = [pipe fileHandleForReading];
[script_task setLaunchPath:@"/bin/sh"];
[script_task setArguments:@[shell_path]];
[script_task launch];
NSData *data = [file_handle readDataToEndOfFile];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
CHLog (@"脚本运行情况 ==> %@", string);
return string;
}
else {
CHLog(@"脚本不存在,请检查!");
return nil;
}
}
- 注意:运行脚本在app外部,可能运行提示无权限,具体原因不清楚。建议放在app沙盒内操作。
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术