Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Continuous Input with NSTask

Continuous Input with NSTask
Thread Tools
Mac Elite
Join Date: Jan 2001
Location: New York
Status: Offline
Reply With Quote
Nov 11, 2002, 09:59 PM
 
I have a job to port an application(from the command line) that requires continuous input from the user. Basically this is the equivalent of using NSTask with Pico. I've looked at Apple's moriarty example. So how would the example need to be changed to handle something like Pico?

Thanks,
David Kopec
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Nov 11, 2002, 11:38 PM
 
What about something like this:

Code:
//declared in the header NSFileHandle *readHandle; NSFileHandle *writeHandle; //declared in the implementation - (IBAction)openFileForReading:(NSString *)fileName { NSTask *task = [[NStask alloc] init]; NSPipe *readPipe = [[NSPipe alloc] init]; NSPipe *outPipe = [[NSPipe alloc] init]; [task setArguments:[NSArray arrayWithObject:file]]; [task setLaunchPath:@"/usr/bin/pico"]; [task setStandardInput:writePipe]; [task setStandardOutput:readPipe]; [task launch]; readHandle = [readPipe fileHandleForReading]; writeHandle = [writePipe fileHandleForWriting]; NSData *data = [readHandle readDataToEndOfFile]; //display this data appropriately in an NSTextView or something } //data should probably be the data form of an NSString //how do you add stuff like control-X to an NSString? Hmmm... - (void)writeUserInputData:(NSData *)data { [writeHandle writeData:data]; //every time the user types something, the display needs to be updated NSData *data = [readHandle readDataToEndOfFile]; //display this data appropriately in an NSTextView or something }
This is just something I threw together in SimpleText (stupid OS 9 machine). No proper memory management or any of that stuff - but it might work.

Does anyone got a better idear?
Matt
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Nov 12, 2002, 04:34 PM
 
That might work for a program that continually reads stdin and writes stdout, but it won't work for pico -- pico requires actual terminal emulation, as it draws characters at arbitrary coordinates, allows cursor repositioning, etc.
Rick Roe
icons.cx | weblog
     
davecom  (op)
Mac Elite
Join Date: Jan 2001
Location: New York
Status: Offline
Reply With Quote
Nov 12, 2002, 04:37 PM
 
Thanks for the replies, but I don't see how your example will continuously read and write input/output. Won't there have to be a timer or thread of some sort?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:19 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2