2 Replies
      Latest reply: Feb 8, 2017 2:34 PM by eskimo RSS
      miwashi Level 1 Level 1 (0 points)

        I want to make a similar tool as grep. ie. "tail -f xxx.log | mygrep"

         

        Is thera an example of how to add support for pipes?

        • Re: How do I make a CLI tool for use with pipes?
          john daniel Level 2 Level 2 (35 points)

          Allow standard input and standard output for input and output options. You might need to add flags to trigger stdio use.

          • Re: How do I make a CLI tool for use with pipes?
            eskimo Apple Staff Apple Staff (7,530 points)

            Is thera an example of how to add support for pipes?

            In general you do not need to add explicit support for pipes.  Rather, if you read from stdin and write to stdout, pipes just work.  Most folks doing that using either:

            • Low-level BSD routines (open, close, read, write)

            • Standard library routines (fopen, fclose, fread, fwrite)

            • Foundation FileHandle objects

            All of these can be called from Swift, but the last is probably the easiest to use.

            Share and Enjoy

            Quinn “The Eskimo!”
            Apple Developer Relations, Developer Technical Support, Core OS/Hardware
            let myEmail = "eskimo" + "1" + "@apple.com"