serial printer hold open scripts with 'cat'
From: Bela Lubkin <firstname.lastname@example.org> Subject: Re: Sleep command quitting Date: 16 Sep 2005 13:33:45 -0400 Message-ID: <email@example.com> References: <firstname.lastname@example.org>
<Xns96D35FF90B361rickpalen@126.96.36.199> Rick Palen wrote: > Another way to do it (and it might even be older than '89, I can't > remember!) is to use a process like cat to keep the ports open. > > (stty ixon ixoff; cat >/dev/null ) </dev/ttya1 & > > We always put these in /etc/rc.d/8/userdef. If a support site > called with garbage on their printers, we always told them that > their cat died :) > > Bela's way with exec sleep 2000000000 is better but I just give > this for some historical context.
Actually I'd say your way is better. Any length of `sleep` could eventually time out. Your `cat` has a different termination condition -- receiving EOF on the tty. Which is highly unlikely if there's actually a printer attached to it. It would be even better if there was an input source which the kernel guaranteed to allow you to open, but which never produced any input. Similar to /dev/null, but it should never return from read() instead of always returning EOF. But for this purpose, one of the printer ports would suffice. One reason the `cat` might be better is that you can lard it with extra arguments which will show up in `ps -ef`: exec </dev/ttya1 3</dev/ttya2 4</dev/ttya3 stty 9600 ixon ixoff -ixany < /dev/ttya1 stty 4800 ixon ixoff -ixany < /dev/ttya2 stty 19200 ixon ixoff -ixany < /dev/ttya3 exec cat - Holdopen script for ttya1, a2, a3 Now I'm using fd 0 (stdin) for the first printer port; shell syntax lets us use that plus fds 3-9, so now we can do 8 per script. (We could probably also use fds 1 & 2, but it's safer not to.)
Got something to add? Send me email.
(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
Increase ad revenue 50-250% with Ezoic
Inexpensive and informative Apple related e-books:
Take Control of OS X Server
Take Control of the Mac Command Line with Terminal, Second Edition
Take control of Apple TV, Second Edition
iOS 10: A Take Control Crash Course
Are Your Bits Flipped?