![](_gb_images/_gb_sitenav_spacer.gif) |
![](_gb_images/_gb_clear.gif) |
NSString as stdin for NSTask
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
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?
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status:
Offline
|
|
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)
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
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 ![Smilie](https://forums.macnn.com/images/smilies/oldschool/smile.gif)
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 ![Smilie](https://forums.macnn.com/images/smilies/oldschool/smile.gif)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
|
|
|
![](_gb_images/_img_misc/_gb_mb_previousthread-off.gif)
|
|
![](_gb_images/_gb_clear.gif) |
Forum Rules
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_sitenav_spacer.gif) |