• 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
Re: Client ssh
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Client ssh


  • Subject: Re: Client ssh
  • From: "Shawn Erickson" <email@hidden>
  • Date: Wed, 31 May 2006 10:27:30 -0700

On 5/31/06, Dominic Blais <email@hidden> wrote:

NSTask can have the pipes redirected (similarly to popen) and that could
cause the dead lock you're describing, but the default case inherits the io
pipes of the task's parent.  Did I miss something in the docs?

Which is likely what the OP need to do since he needs to communicate with another endpoint, in other words he needs do IO with the task (assuming he uses the NSTask route). It likely serves him no purpose to have output from the launched task go to his applications standard out.

This is the situation I am talking about... (just wanted to preempt
folks from building from your one line example to something that could
cause problems).

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   NSTask* task = [[[NSTask alloc] init] autorelease];
   NSPipe* pipe = [NSPipe pipe];
   NSFileHandle* taskOutput = [pipe fileHandleForReading];

   [task setLaunchPath:@"/bin/cat"];
   [task setArguments:[NSArray arrayWithObjects:@"small.txt", nil]];
   //[task setArguments:[NSArray arrayWithObjects:@"large.txt", nil]];
   [task setStandardOutput:pipe];

   [task launch];
   [task waitUntilExit]; // with a large enough file you deadlock here

   NSData* data = [taskOutput readDataToEndOfFile];

   NSLog(@"Data Length: %ld", [data length]);

   [pool release];
   return 0;
}

To avoid the deadlock consider using -[NSFileHandle
readInBackgroundAndNotify] (and friends) to trigger async reading
while you sit in waitUntilExit. The other option is to fully drain the
pipe before calling waitUntilExit (depends on how much data you expect
and how you want to process it).

-Shawn
_______________________________________________
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: Client ssh
      • From: Dominic Blais <email@hidden>
References: 
 >Client ssh (From: Valerio Ferrucci <email@hidden>)
 >Re: Client ssh (From: Dominic Blais <email@hidden>)
 >Re: Client ssh (From: "Shawn Erickson" <email@hidden>)
 >Re: Client ssh (From: Dominic Blais <email@hidden>)

  • Prev by Date: Re: Creating/Populating Windows programatically
  • Next by Date: Re: Creating/Populating Windows programatically
  • Previous by thread: Re: Client ssh
  • Next by thread: Re: Client ssh
  • Index(es):
    • Date
    • Thread