I'm building an app that automates notarization of my apps.
I ran into the following issue:
When I use NSTasks to perform commands such as xcrun altool and xcrun stapler, the return value is much longer than what I get in Terminal.
For example, when I run stapler in Terminal, I get three lines of output:
Processing: <app path>
Processing: <app path>
The staple and validate action worked!
NSTask, however, also returns tons of log lines from the processing stage that look like this:
[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.
Now that wouldn't be a critical issue as in most cases NSTask does include the return values that I get in Terminal - and which are required for my app to know the outcome of the task and proceed accordingly.
But in some cases NSTask returns ONLY the irrelevant log entries I mentioned above - and seemingly before the task even finished running. In particular, it happens when running the xcrun altool --notarize-app command. My app, therefore, doesn't know how to proceed as it doesn't receive a confirmation of the successful upload.
I'm using NSTask in a synchronous way with a standard routine to obtain the output:
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];
I don't recall ever having this issue when using NSTask with other commands.
So I wonder if I'm missing something? And if there's a way to obtain only the relevant return value - just the way I get it in Terminal?