我想從一個GUI應用程序運行dpkg(或任何其他二進制庫文件在/ bin或/ usr/bin目錄中的cydia)圖標,如移動終端,ifile,myfile,cydia,alertscript等等。他們如何訪問這些庫?這段代碼有效,並且進程的stdout被打印在nslog中,但是它立即崩潰並出現Segmentation故障:11.這是在我的viewdidload函數中。這不會出現在模擬器中,只有我的iPhone 4.奇怪。試圖以移動和root身份運行。該應用程序位於/ Applications文件夾下。這是我的代碼。試圖使用蘋果蠹圖書館:越獄iphone上的NSTask與分割錯誤崩潰:11
編輯:我使用xcode的雪豹版本,只是更新到獅子,但我想這可能不是問題?我的iPhone是ios5.0.1。將在我測試時發佈。
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];