【发布时间】:2014-02-18 19:00:23
【问题描述】:
有没有办法从 system() 获取日志;所以就像当我做system("open com.apple.nike"); 时我应该得到Couldn't open application: com.apple.nike. Reason: 8, application disabled or restricted。这将在我的 iOs 7 设备上运行
谢谢
编辑:// 这是新代码,但它不会工作,我会得到 p>
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'launch path not accessible'
*** First throw call stack:
NSString *bundleID = @"com.apple.nike";
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"sudo"];
[task setArguments: [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"open %@", bundleID], nil]];
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];
NSLog(@"result: %@", output);
【问题讨论】:
-
试试popen(3)
-
@Mikael 我只想获取系统命令的日志或响应。开放本身效果很好