Re: NSTask setStandardOutput: then stringWithContentsOfFile gives empty string
Re: NSTask setStandardOutput: then stringWithContentsOfFile gives empty string
- Subject: Re: NSTask setStandardOutput: then stringWithContentsOfFile gives empty string
- From: Alastair Houghton <email@hidden>
- Date: Mon, 27 Aug 2007 23:45:12 +0100
On 27 Aug 2007, at 23:21, Rosyna wrote:
Ack, at 8/27/07, Alastair Houghton said:
2. Accept that at some point you may need to do some work to fix
your program.
Or you could just use the proper APIs that won't break in the future.
Where they exist, yes. And, as I said, they *do* exist in the case
of "ps".
And when the output of a command line tool (especially a complex
one like ps) changes, you may not be able to foresee the changes
and bad thingsā¢ will happen.
That's the point of part 1 of what I said (which you deleted)... the
bit about being liberal in what you accept. i.e. *expect* the output
to change, and try to deal with that as gracefully as possible.
(I should also have added a "3. If the tool supports, it, explicitly
specify its output format.".)
A good example of a tool whose output you *should* be parsing
rather than trying to emulate its (horrific) workings is "lsof".
Parsing the output of lsof is a whole lot more likely to continue
working in the future than trying to do what it does.
lsof is not a good example. If I needed to do what lsof did, I'd
take it from the source code of lsof (http://
www.opensource.apple.com/darwinsource/10.4.9.ppc/lsof-28/lsof/) and
adapt it to my specific needs. lsof has a lot of options that may
not be necessary to implement for your needs.
That would be a Really Bad Idea. Apple maintain lsof such that it
will work on whatever version of Mac OS X they release next. Since
it gets pretty intimate with the kernel, the chances are good that
the code will have to change on some future release of OS X.
So incorporating that code into your app... will break. And it will
break sooner than parsing lsof's output will, particularly as lsof
**has an option specifically for the purpose of being parsed** (the "-
F" option, if anyone is interested).
I picked lsof specifically because it *is* a good example of a
situation where parsing really is appropriate. Thankfully, very few
people have programs that need the information that lsof provides.
And lsof hails from 1994. It's old, so it must be bad.
Hmmmm... isn't Objective-C from the 1980s... :-)
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden