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];