【发布时间】:2019-06-28 06:33:50
【问题描述】:
我正在构建一个可以自动对我的应用进行公证的应用。
我遇到了以下问题:
当我使用 NSTasks 执行 xcrun altool 和 xcrunstapler 等命令时,返回值比我在终端中得到的要长得多。
例如,当我在终端中运行 stapler 时,我得到三行输出:
Processing: <app path>
Processing: <app path>
The staple and validate action worked!
然而,NSTask 也会从处理阶段返回大量的日志行,如下所示:
[2019-06-27 04:18:57 EDT] <main> INFO: Logging level set to eXtreme
[2019-06-27 04:18:57 EDT] <main> INFO: Logging configured successfully.
[2019-06-27 04:18:57 EDT] <main> DEBUG: Attempting refresh of configuration data from https://contentdelivery.itunes.apple.com/transporter/Defaults.properties
[2019-06-27 04:18:57 EDT] <main> DEBUG: Configuration refresh successful.
etc.
现在这不是一个关键问题,因为在大多数情况下 NSTask 确实包含我在终端中获得的返回值 - 我的应用需要这些值来了解任务的结果并相应地继续。
但在某些情况下,NSTask 只返回我上面提到的不相关的日志条目——而且似乎在任务完成运行之前。特别是在运行 xcrun altool --notarize-app 命令时会发生这种情况。因此,我的应用不知道如何继续,因为它没有收到上传成功的确认信息。
我正在使用 NSTask 以与标准例程同步的方式来获取输出:
thePipe = [NSPipe pipe];
[task setStandardOutput:thePipe];
[task setStandardError:thePipe];
[task launch];
[task waitUntilExit];
NSFileHandle *fh = [thePipe fileHandleForReading];
NSString *result = [[[NSString alloc] initWithData:[fh availableData] encoding:NSASCIIStringEncoding] autorelease];
我不记得在将 NSTask 与其他命令一起使用时遇到过这个问题。
所以我想知道我是否遗漏了什么?如果有办法只获得相关的返回值 - 就像我在终端中获得它的方式一样?
【问题讨论】:
标签: xcode cocoa terminal nstask