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 > NSString as stdin for NSTask

NSString as stdin for NSTask
Thread Tools
VEGAN
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Oct 6, 2002, 08:47 AM
 
OK, I have a NSString that contains a few pages of information. What I want to do is to feed it in for a NSTask to do some shell operations.

How do I do this?
     
Mactoid
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Oct 6, 2002, 07:36 PM
 
NSTask setStandardInput:

- (void)setStandardInput:(id)file

Sets standard input for the receiver to file, which can be either an NSFileHandle or an NSPipe object. If file is an NSPipe, launching the receiver automatically closes the read end of the pipe in the current task. If you're using a pipe for standard input, use an NSPipe instance as the argument to this method. Don't create a handle for the pipe and pass that as the argument. If you do, the read end of the pipe won't be closed automatically.

If this method isn't used, the standard input is inherited from the process that created the receiver. You cannot use this method if the receiver has already been launched. If you do, it raises an NSInvalidArgumentException.

See Also: - standardInput
Looks pretty easy to me. Just create a pipe, set the stdin of your task to the pipe, then write your string into it.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
VEGAN  (op)
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Oct 7, 2002, 06:49 AM
 
Originally posted by Mactoid:
Looks pretty easy to me. Just create a pipe, set the stdin of your task to the pipe, then write your string into it.
Sounds good enough
Actually, you where right, I don't have NSString, but a NSPipe from a previous NSTask... I don't know why I didn't think of feeding the NSPipe into it...

Thanks
     
   
 
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
Top
Privacy Policy
All times are GMT -4. The time now is 12:45 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,