On Feb 20, 2013, at 10:28 PM, Kyle Sluder wrote:

> On Wed, Feb 20, 2013, at 08:22 PM, Kyle Sluder wrote:
>> You can accomplish this without writing to the file system, but it
>> involves foregoing NSTask. Fork, close stdin in the child process, open
>> a pipe (so that the child gets the read end in fd 0), then exec the tool
>> with "/dev/stdin" as the filename argument.
> 
> Actually, the appropriate order of operations here is pipe, fork,
> close(stdin), dup(filedes[0]), exec.

It's not clear to me why that technique wouldn't work with NSTask and NSPipe.  
The read end of the NSTask's standardInput pipe is dup'd to stdin and you can 
easily enough pass "/dev/stdin" in the argument list.

You would only need to do manual syscalls if you wanted to use a different file 
descriptor and "/dev/fd/<some number>".

Finally, you should generally prefer dup2() over close() plus dup().

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to