Pipes, tasks and other things! :-)

Discussion in 'Mac Programming' started by mdeh, Mar 28, 2010.

  1. mdeh macrumors 6502

    Joined:
    Jan 3, 2009
    #1
    Hi all,
    May I ask for some help with a conceptual understanding of an issue that I have not been able to clearly discern from the documents.

    It concerns the role of an NSFileHandle object in relation to pipes, in for example, running a task from within a cocoa ap.

    Right now, I understand a pipe ( conceptually) to be mechanism whereby the output of one unix operation/command is directed to the input of another, and vice-versa (understanding that pipes are unidirectional). So, the example that was used to illustrate this, was cat|wc ( for a pipe *from* cat *to* wc).

    In the actual construction of an operation to perform this, the role of NSTask makes sense, the role of NSPipe does so too, but I cannot conceptually place the role of NSFileHandle. Could someone give a nice concise concept to this for me and then, what does it **actually** do?

    Thanks in advance.
     
  2. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #2
    Read the documentation again. Does NSPipe itself respond to any methods for transfering actual data?
     
  3. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #3
    NSFileHandle is a reference to where data will go; UNIX is built around the concept of "files" as an abstract bit container. Devices can be accessed as a "file" and written to/read from.

    There are several standard system-defined file handles for things like the console, standardized so every app can write text messages to it for viewing in a console viewing app (reading from the file handle).
     
  4. mdeh thread starter macrumors 6502

    Joined:
    Jan 3, 2009
    #4

    Firstly, thanks Sayer. So, if I understand you correctly, by defining a FileHandle, I am "redirecting" the output/input to something that is useful to me ...the programmer. So, if I wish to write a string to NSLog, I can "direct" the output of the pipe to an NSData Object that I control, and then read it and display it just like any other (data) object.

    Thanks again for your input.
     

Share This Page