• 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: Wrapping an Interactive Unix Executable (update)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wrapping an Interactive Unix Executable (update)


  • Subject: Re: Wrapping an Interactive Unix Executable (update)
  • From: Erik Mendoza <email@hidden>
  • Date: Fri, 17 Dec 2004 01:35:40 -0800

Hi,

I'd be happy to show you the code, but I don't think there is any need, as my latest attempt is for all intents and purposes exactly what you just posted. This came about because in searching the mailing list somebody had pointed out that the source code for a project called MathPaper in Building Cocoa Applications: A Step-By-Step guide is a wrapper for an interactive unix task. I'm beginning to think that maybe the problem is with the way the Unix executable is designed, though there should be some workaround.

Anyway, a little bit more about my program. It's based on a program called LatinWORDS, which can parse a given word (downloadable here: http://users.erols.com/whitaker/wordsmac.htm). As you can see, the current wrapper is a bit rough around the edges, which is why I undertook the task of updating it. My version does not require an installer or an administrator password, which are good things for user friendliness.

If anyone's interested I can get a friend to host the XCode project, or I can email it individually. Thanks again to all those that have already taken the time to help, and anyone who continues to help. I very much appreciate it.

Erik

Incidentally, in the current, working version of the application, I've resorted to launching the program each time with the word string as its argument at launch. This works, but it's dirty. Also, I'm very new at all this, so my code won't be the greatest.


On Dec 17, 2004, at 1:09, Harilaos Skiadas wrote:

Thanks for all of the replies, but I'm still having
some problems.

I've looked over the NSTask documentation, and I
think I can use the
standard input and output stuff, but I haven't yet
figured out how. At
this point I'm able to launch the NSTask and get the
initial output,
which is good. But as soon as I try to send it new
input (by writing
to the NSFileHandle associated with the
standardInput) it crashes. I
think I can get it to work if I use the notification
center, but I'd
have to do everything in my controller class, but I'd
rather keep
things separated as they are now in a controller
class and translator
class. Thanks again for the help.

Can you show us some of your code? I haven't had many problems with this. Basically, I get the task running with (arguments is an NSArray containing the information for the tool, task is an NSTask):

[task setStandardInput: [NSPipe pipe]];
[task setStandardOutput: [NSPipe pipe]];
[task setStandardError: [task standardOutput]];
[task setLaunchPath: [arguments objectAtIndex:0]];
[task setArguments: [arguments subarrayWithRange:
NSMakeRange (1, ([arguments count] - 1))]];
 [[NSNotificationCenter defaultCenter]
addObserver:self
					selector:@selector(getData:)
					name: NSFileHandleReadCompletionNotification
					object: [[task standardOutput]
fileHandleForReading]];
[[[task standardOutput] fileHandleForReading]
readInBackgroundAndNotify]; //You need to call this
from getData: too
// In order to have it read more.
[task launch];

Then when I want to send more data, I call:

NSData *dataToSend=[aString dataUsingEncoding
NSUTF8StringEncoding];
[[[task standardInput] fileHandleForWriting]
writeData:dataToSend];

Then to terminate:

  [[NSNotificationCenter defaultCenter]
removeObserver:self
name:NSFileHandleReadCompletionNotification object:
[[task standardOutput] fileHandleForReading]];
    [task terminate];
    [task release];

Can you tell us what the unix executable you are
trying to use is? Maybe you mentioned it already, but
I missed the beginning of this thread. Some programs
are very picky about being run from something which is
not a terminal. Some of them need you to set a switch
so that they know they are not talking to a terminal.
Btw, if you search the archives you can find more info
on this, eg:
http://www.cocoabuilder.com/archive/message/2004/8/26/115642

I hope this helps,
Haris

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

_______________________________________________ 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
References: 
 >Re: Wrapping an Interactive Unix Executable (update) (From: Harilaos Skiadas <email@hidden>)

  • Prev by Date: NSTextFieldCell "challenge"
  • Next by Date: Re: NSTextFieldCell "challenge"
  • Previous by thread: Re: Wrapping an Interactive Unix Executable (update)
  • Next by thread: Re: Wrapping an Interactive Unix Executable (update)
  • Index(es):
    • Date
    • Thread