ClashX.Meta/ProxyConfigHelper/CommonUtils.m

32 lines
716 B
Mathematica
Raw Normal View History

2020-12-16 21:51:00 +08:00
//
// CommonUtils.m
// ClashX
//
// Created by yicheng on 2020/4/2.
// Copyright © 2020 west2online. All rights reserved.
//
#import "CommonUtils.h"
@implementation CommonUtils
+ (NSString *)runCommand:(NSString *)path args:(nullable NSArray *)args {
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:path];
[task setArguments:args];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file = [pipe fileHandleForReading];
[task launch];
NSData *data = [file readDataToEndOfFile];
NSString *output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
#if DEBUG
NSLog(@"%@",output);
#endif
return output;
}
@end