Using an NSString as standard input to an NSTask
Using an NSString as standard input to an NSTask
- Subject: Using an NSString as standard input to an NSTask
- From: Ken Tabb <email@hidden>
- Date: Wed, 26 Oct 2005 14:41:31 +0100
Hi folks,
is there an easy way to supply an NSString as the standard input for
an NSTask? I've looked at NSTask, NSString (and associated),
NSFileHandle and NSPipe but can't see an obvious way to do it.
I'm currently writing temporary files, firing off an NSTask using the
temporary file as its standard input, and deleting the temporary
file. This works fine, but I will typically need to fire off the
NSTask using a couple of thousand files each time (in a for loop, new
NSTask & file per iteration), it means potentially abusing the user's
disk space. Not least it must be quicker supplying an in-memory
NSString than it is to write a file, and then load that file in the
NSTask.
I guess I'm after the programmatic equivalent of:
myCLIApp < @"a string"
... using NSTasks and NSStrings
Carrying on from this, if it is possible to use in-memory NSStrings
as input to NSTasks, what's the deal with memory management? i.e.
would the NSTask retain the string, in which case I can release the
string the moment I call the NSTask (having given it the string to
look after), or would I have to wait until the end of the for loop
before freeing up all the strings? I ask because the strings can be
quite big, and there are a few thousand of them, so might have a VM /
paging impact on the end user's app performance.
Any suggestions welcome,
Ken
- - - - - - - - - -
Dr. Ken Tabb
Mac & UNIX Developer - Health & Human Sciences
Machine Vision & Neural Network researcher - School of Computer Science
University of Hertfordshire, UK
http://www.health.herts.ac.uk/ken/
Certified non-Microsoft Solution Provider
_______________________________________________
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