Use pseudo terminals as named pipes in Finder

Jan 08, '08 07:30:00AM

Contributed by: Anonymous

I am currently using VLC for my streaming radio fix. As VLC does not update its track and title information, the are three ways for me to check the current streaming radio track. The first two are to Get info on the current stream in VLC, or use VLC's embedded message viewer, both of which require a lot of mousing around, aren't a quick view solution, and neither allow me to constantly see the changing track names.

The other is to write the message viewer's contents to a log. I was using a standard log file, but after constantly having to erase the file after it became too big, I realized that this going to kill the hard drive in no time, especially if I do the same thing on a flash-drive-based linux distro (Which I am planning).

After digging, I found out about FIFOs and named pipes, even seeing a hint here about them. I also read about how the GUI side of OS X does not handle named pipes graciously (Finder or VLC crashes). But reading around, I noticed pseudo terminals and had an epiphany. GUI apps can access /dev devices (such as sound cards and serial ports) by name, so why can't they write to them?

I end up assigning VLC to log to /dev/ttyu1 then I cat /dev/ptyu1. tail does not work on /dev/ptyu1 because the pseudo-terminal does not have an for it to work from, and cat keeps reading until it receives one (when VLC quits). This way, VLC in the GUI thinks I am logging to a file, and I can see what is being logged (via Terminal) without actually writing the log to the hard drive.

Another use is to log to a file and let Geek Tool display the info, without having to actually write the file. This works as a named pipe, using the following:

Write to /dev/ttyxn where x is a letter between p and w, and n is a number from 0 to 9 and a to f (hex 0-15). Read from /dev/ptyxn, where x and n are the same as they were before.

There are two problems with this solution. First, only one program can read from /dev/ptyu1 at a time. Not too big of a problem. I don't think multi-app access to a file is needed much. On the other hand, more then one program can write to /dev/ttyu1 at a time. You have just created a very minimal version of Logger/Syslog :D

The second problem is not with this usage, but with trying to pipe the output from /dev/ptyu1 to grep, then pipe it out to another program. It seems grep needs an before its output can be sent to another program, which can't be done with this method (or with using tail -f something | grep something | another program).

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080101205230239