问题
I want to run dpkg ( or any other binary library files from cydia in the /bin or /usr/bin directories) from a GUI app with an icon, like mobileterminal, ifile, myfile, cydia, alertscript, and so many others can. How do they accesses the libraries? This code works, and the stdout of the process is printed in nslog but then it immediately crashes with Segmentation fault: 11. this is in my viewdidload function. This DOES NOT OCCUR IN THE SIMULATOR, only my iPhone 4. weird. have tried running as both mobile and root. the app is under /Applications folder. Here's my code.
EDIT: I'm using the snow leopard version of xcode, and just updated to lion but I'm thinking that's probably not the issue? My iPhone is ios5.0.1. will post when I test it.
NSString * workingdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSTask * nstaskvar=[NSTask new];//note the NSTask.h file included!
NSPipe * outputPipe = [NSPipe pipe];
[nstaskvar setLaunchPath:@"/bin/ls"];
[nstaskvar setArguments:[NSArray arrayWithObjects:@"/usr",nil]];
[nstaskvar setCurrentDirectoryPath:workingdir];
[nstaskvar setStandardOutput:outputPipe];
[nstaskvar setStandardInput:[NSPipe pipe]];
[nstaskvar launch];
NSString * outputstring = [[[NSString alloc] initWithData:[[outputPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding] autorelease];//readDataToEndOfFile reads until file is closed, which happens when process exits :) (i couldnt get waitUntilExit to work)
NSLog(@"%@", outputstring);
[nstaskvar release];
[outputPipe release];
回答1:
Solved it! After I upgraded to xcode 4.3.2, the lion version, the simulator crashed with exc_bad_access
so i enabled zombies and found it was the last two lines [nstaskvar release]; [outputPipe release];
that caused the problem.
I disabled them both and it went away, and now works great on my iphone :D.
来源:https://stackoverflow.com/questions/9983430/trying-to-use-cydia-libraries-nstask-on-jailbroken-iphone-crashes-with-segmenta