This is my first real Cocoa project. I wrote a function that takes a NSString as input, uses an NSTask to run an ADB command, and returns the terminal output to an NSString. The code builds fine, but when I press the button to run that function, the app freezes. When I force close, I see Thread 1: signal SIGTERM
on the line data = [file readDataToEndOfFile];
.
Function
NSString* runADBCommand(NSString *cmd)
{
[[NSTask launchedTaskWithLaunchPath:adbPath
arguments:[NSArray arrayWithObjects: cmd, nil]]waitUntilExit];
NSTask *adbDevices = [[NSTask alloc] init];
adbDevices.launchPath = adbPath;
NSString* devices = @"devices";
adbDevices.arguments = @[devices];
NSPipe *pipe;
pipe = [NSPipe pipe];
[adbDevices setStandardOutput:pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
NSData *data;
data = [file readDataToEndOfFile];
NSString *adbComOutput;
adbComOutput = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"\n\n%@", adbComOutput);
return adbComOutput;
}
Call
- (void) getVersion:(id)sender
{
runADBCommand(@"shell cat /system/build.prop | grep incremental");
}
I've been looking for references online, but am not sure what to look for. Any help is appreciated!