• 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: One for the Unix gurus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: One for the Unix gurus


  • Subject: Re: One for the Unix gurus
  • From: Phill Kelley <email@hidden>
  • Date: Mon, 28 Jun 2004 08:30:29 +1000

At 20:31 -0400 25/06/2004, Glenn Zelniker wrote:
>I need to integrate some ssh functions (primarily scp) into an
>application and I've been experimenting with writing wrappers around
>Unix commands. I'm taking the usual approach -- using NSTask, NSPipe,
>and NSFileHandle. I launch the task from the proper location, pass the
>command-line arguments via an NSArray, pipe stdin, stdout, and stderr
>as needed, and react to NSNotifications triggered by asynchronous
>background reads. This works fine for simple commands like "ls" and
>I've verified that I can execute "ls" with multiple command-line
>arguments, such as "ls -l -a /myfiles." I've also verified that I get
>output through the pipe I set up for stdout and errors through the pipe
>for stderr. So far, so good...
>
>The problem is that I can't seem to get things like scp or ftp working.
>For example, when running ftp from the command line, one normally sees
>on the terminal a stream of information welcoming you to the host,
>disclaimers, and finally an FTP> prompt. When I run ftp from the GUI
>I've written (and I'm sure the arguments are being parsed correctly), I
>only see the FTP> prompt in the NSTextView I've set up to log stderr.
>Where does the other "stuff" go? It doesn't seem to go to the pipe I've
>set up for stdout. When I set the associated handle for
>readInBackgroundAndNotify, I'm looking out for
>NSFileHandleReadCompletionNotification. Should I be using a different
>notification and is this why I'm missing the welcome notice? Is there a
>place besides stdout and stderr that it's going to?
>
>I won't even talk about the stuff I'm trying to send to the command's
>input -- I want to understand what's happening with the output first!
>Any help would be appreciated immensely.

Have you tried setting the NSUnbufferedIO environment variable? I had this
problem in one of my apps. The CLI tool I was calling even had a
command-line option for requesting unbuffered I/O but setting it achieved
nothing. It wasn't until I found NSUnbufferedIO somewhere (probably in the
online doco) that my problem went away:

// clone the current environment
NSMutableDictionary* environment =
[NSMutableDictionary dictionaryWithDictionary:
[[NSProcessInfo processInfo] environment]
];

// set up for unbuffered I/O
[environment setObject:@"YES" forKey:@"NSUnbufferedIO"];

// hand the environment to the NSTask
[task setEnvironment:environment];


Regards, Phill
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: One for the Unix gurus
      • From: Rolando Abarca <email@hidden>
References: 
 >One for the Unix gurus (From: Glenn Zelniker <email@hidden>)

  • Prev by Date: Re: Rotating Images....
  • Next by Date: Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
  • Previous by thread: Re: One for the Unix gurus
  • Next by thread: Re: One for the Unix gurus
  • Index(es):
    • Date
    • Thread