Ok so I'm trying to make an app that is basically a GUI for a script the part I can't get to work correctly is displaying the output of the script at first I had it so it should me everything after task had completed which needless to say is no good. Where I'm at now is I can get the output in real time in a uitextview but as new information is being delivered it over laps making it unreadable I use the script apt-get update in my example. I am a new jailbreak dev and yes I have my app running with root permission my only problem is the output... My code is this:
#import "RootViewController.h"
@implementation RootViewController
@synthesize navItem;
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor redColor];
navBar = [[UINavigationBar alloc] init];
navBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
navItem = [[[UINavigationItem alloc]
initWithTitle:@"GUI"] autorelease];
navBar.barStyle = UIBarStyleDefault;
navBar.items = [NSArray arrayWithObject:navItem];
[self.view addSubview:navBar];
NSPipe *pipe = [NSPipe pipe];
_fileHandle = [pipe fileHandleForReading];
[_fileHandle readInBackgroundAndNotify];
task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/apt-get"];
[task setStandardOutput: pipe];
[task setStandardError: pipe];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"update", nil];
[task setArguments: arguments];
[task launch];
}
-(id)init
{
[super init];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector( readPipe: )
name:NSFileHandleReadCompletionNotification
object:nil];
return self;
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)readPipe: (NSNotification *)notification
{
NSData *data;
NSString *text;
if( [notification object] != _fileHandle )
return;
data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];
text = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
navItem.title = text;
titleTextField = [[UITextView alloc] initWithFrame: CGRectMake(0, 40, 320, 350)];
[titleTextField setBackgroundColor:[UIColor clearColor]];
titleTextField.text = text;
titleTextField.editable = YES;
titleTextField.scrollEnabled = YES;
titleTextField.autoresizingMask =UIViewAutoresizingFlexibleHeight;
[self.view addSubview: titleTextField];
[text release];
if( task )
[_fileHandle readInBackgroundAndNotify];
}
@end