Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:01:07+00:00 2026-06-04T21:01:07+00:00

So, I managed to get NSTask to read asynchronously from a program, but I

  • 0

So, I managed to get NSTask to read asynchronously from a program, but I did it inside the class of a UIView in my storyboard. (Not an Obj-C expert)

My ideia is: I read the text from the program place it on a UITextView and then when there’s more repeat the process via NSNotificationCenter

So far this is my code:

LView.m:

- (void)viewDidLoad
{

    [super viewDidLoad];

    NSPipe *out_pipe = [NSPipe pipe];
    sshoutput = [out_pipe fileHandleForReading];
    [sshoutput readInBackgroundAndNotify];

    utilT = [[NSTask alloc] init];
    [utilT setLaunchPath:@"/usr/bin/utilfc9"];
    [utilT setArguments:[NSArray arrayWithObjects: @"-p", @"-f", @"log.txt", nil]];

    [utilT setStandardOutput: out_pipe];
    [utilT setStandardError: out_pipe];
    [utilT launch];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readPipe:) name:NSFileHandleReadCompletionNotification object:nil];
}

-(void)readPipe: (NSNotification *)notification
{
    NSData *data;
    NSString *new_input;

    if( [notification object] != sshoutput ) { return };

    data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];
    new_input = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

    self.log.text = [self.wifilog.text stringByAppendingFormat: @"\n%@", new_input];

    if( utilT ) {
        [sshoutput readInBackgroundAndNotify];
    }
}

LView.h:

#import <UIKit/UIKit.h>
#import "NSTask.h"

NSTask *sshT;
NSFileHandle *sshoutput;

So far it works great, I get the data live without any issues.

But, how can I place this NSTask in a more “global” place like AppDelegate’s application didFinishLaunchingWithOptions and then process the data and update multiple views in another classes? I tried and of course I can stuff like log.text = new_input inside AppDelegate because it’s from another class, and including it does not solve the problem.

As you might noticed, I’m not interested in sending this to the AppStore. It’s an app for myself to use on a jailbroken iPhone.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:01:08+00:00Added an answer on June 4, 2026 at 9:01 pm

    Quick way to do it is

    In all of the Views that you want to recieve this same notification add the following

    ReceiverView

    -(void) viewDidLoad
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(read:)     name:@"ReadTest" object:nil];
    }
    
    //read function
    -(void) read:(NSNotification*)notification
    { // Do something with the notification }
    

    Now in LView.m

    -(void)readPipe: (NSNotification *)notification
    {
        NSData *data;
        NSString *new_input;
    
        if( [notification object] != sshoutput ) { return };
    
        data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];
        new_input = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    
        self.log.text = [self.wifilog.text stringByAppendingFormat: @"\n%@", new_input];
    
        if( utilT ) {
            [sshoutput readInBackgroundAndNotify];
        }
        //Add the following
        [[NSNotificationCenter defaultCenter] postNotificationName:@"ReadTest" object:notification]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed to get my UIView to animate when moving its frame.origin.x from
Ive managed to get something like this to work in another project but not
I managed to get some help from a previous question and I have the
I managed to get the YUI calendar widget working fine. But When it displays
I managed to get authentication to work by following the tutorial from this page
I managed to get custom themes running for Tabs but still got a lil
I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
I've managed to get a PNG overlay to appear over an asp:hyperlink image, but
I managed to get the access token for google's contacts API but when i
I managed to get this code to compile with out error. But somehow it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.