• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[long] Re: Running processes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[long] Re: Running processes


  • Subject: [long] Re: Running processes
  • From: Development <email@hidden>
  • Date: Tue, 12 Sep 2006 08:51:30 -0700

I tried to post this before but it was too long so I've cut out a few parts that have no relevance to the problem. Basically this the code being used in the application I am having trouble with. the printTaskOutput is either not catching all of the data or it is not receiving all of the data. I have tried using NSLog to view the output and it is missing major parts so I am fairly sure that it is not receiving all of the data.

- (void)printTaskOutput:(NSNotification *)aNotification
{
NSString *outputString;
NSData *data = [[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem];
if (data && [data length])
{
outputString = [NSString stringWithCString:[data bytes] length:[data length]];
[self appendStringToConsole:outputString];
[[aNotification object] readInBackgroundAndNotify];
}
}



- (void)processFile:(NSString *)path toPath:(NSString *)location { [taskOut makeKeyAndOrderFront:self];

NSMutableArray *args = [NSMutableArray array];
NSPipe *taskPipe = [NSPipe pipe];
NSDictionary *defaultEnvironment = [[NSProcessInfo processInfo] environment];
NSMutableDictionary *environment = [[NSMutableDictionary alloc] initWithDictionary:defaultEnvironment];
[environment setObject:@"YES" forKey:@"NSUnbufferedIO"];


    task = [[NSTask alloc] init];

	[task setEnvironment:environment];
    /* set standard I/O, here to a NSPipe */
    [task setStandardOutput:taskPipe];
    [task setStandardError:taskPipe];

    [args addObject:path];
    [args addObject:location];
    [task setArguments:args];

[task setLaunchPath:[[NSBundle mainBundle] pathForResource:@"fp" ofType:nil]];

    [[taskPipe fileHandleForReading] readInBackgroundAndNotify];

    [task launch];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(printTaskOutput:) name:NSFileHandleReadCompletionNotification object:[[task standardOutput] fileHandleForReading]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskCompleted:) name:NSTaskDidTerminateNotification object:unrar];
[task waitUntilExit];
}



On Sep 11, 2006, at 7:51 AM, I. Savant wrote:



NSTask just isn't working, thats the problem.

Such a broad, sweeping statement is usually the last thing you should make, especially since NSTask is successfully used for a number of ... well ... tasks ... in many apps. In other words, it's a bit of a conceit to assume NSTask is simply broken because you can't get it to work right.


I'm listening for notifications on the pipes to read the output from the clu and what I am getting is missing beginning and ending characters and if it has more than one word, about half the time the other words in the output are simply lost. That's why I am really hoping there is a primitive out there I can use instead of NSTask.

There may be ... then again, NSTask will probably work just fine too, but without posting your code or describing exactly what you're trying to accomplish, it's impossible for us to say. As Shawn asked you, "Can you outline how you are using NSTask?"


  Post your code and your goal. Anything less will get us nowhere.

--
I.S.





_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: [long] Re: Running processes
      • From: Nir Soffer <email@hidden>
    • Re: [long] Re: Running processes
      • From: "Tom Harrington" <email@hidden>
    • Re: [long] Re: Running processes
      • From: Scott Ribe <email@hidden>
References: 
 >Running processes (From: Development <email@hidden>)
 >Re: Running processes (From: Wain <email@hidden>)
 >Re: Running processes (From: Development <email@hidden>)
 >Re: Running processes (From: "I. Savant" <email@hidden>)

  • Prev by Date: Data parsing problem -long
  • Next by Date: Re: Creating many NSPipes
  • Previous by thread: Re: Running processes
  • Next by thread: Re: [long] Re: Running processes
  • Index(es):
    • Date
    • Thread