Hacker News

3 hours ago by jcrawfordor

While the article is correct, it omits most of the actual function of CUPS. Many printers are capable of accepting various types of documents directly over the network, with postscript, HP PCL, and PDF being commonly supported---and ASCII pretty much universally supported.

The problem is that few printers support _all_ of these standards. Postscript, for example, is surprisingly complex to implement in practice, which leads to a lot of inexpensive network printers actually lacking postscript support. Further, printers are very slow at rasterizing, and so while support for PDF rasterization is very common you probably don't want to use it. You can easily see a minute per page for printing modest PDFs. In-printer PDF rasterization is also of very uneven quality, and I have seen issues like completely broken kerning in documents due to the printer's poor handling of embedded fonts.

One of the key functions of something like CUPS is to address this problem: CUPS standardizes the format of all printed documents to something that is well-supported by the printer, and performs much of the rasterization ahead of time on the much faster print server. This saves time and improves reliability since you don't need to figure out if a given document is supported by the printer. For most printers these days some variant of PCL is the preferred language for jobs, as it's simpler and easier to implement than Postscript. It also presents fewer security concerns.

Of course the other major problem CUPS solves is the management of the queue, including across multiple users. That's an important feature but not one that matters in a lot of home situations. That said, if you don't use a printing system you can and will run into annoying situations where you cannot print a document because you are waiting for the previous one to complete sending, which often gets blocked on the printer's memory space or rasterization.

an hour ago by tonyedgecombe

I suppose if you have a printer that doesn't support PostScript or PDF then you could pipe the output through GhostScript. This is what CUPS is relying on anyway.

3 hours ago by the_arun

What about Page Layout / Color/Mono selection etc.,?

8 hours ago by jim-jim-jim

Hah. I had a similar moment of enlightenment with FreeBSD when somebody explained that you can just cat a wav file into /dev/audio (or /dev/dsp? forget the exact name). And that you can produce white noise by catting /dev/random to the same destination. With no barrier to the sound card like that, I was free to experiment with programming dfferent noise algorithms and figuring out how digital audio works. I eventually did things the proper way with OSS and finally sndio on OpenBSD, but direct, universal interfaces like files invite that initial exploration and help you get things done quick and easy.

netcat is also a secret weapon around the house. My girlfriend runs macOS, but it's way more reliable to just nc files to each other over wifi than deal with all the cloud and airdropping bullshit.

7 hours ago by krrrh

When I was first learning Linux many years ago a friend and I got intoxicated and catted /dev/hda into /dev/dsp. It was all basically static with sometimes very structured patterns that we would try to guess as to what filetype was producing them. He had download and forgotten about a long uncompressed audio recording of a piano performance on his drive that suddenly started breaking through the static in chunks of varying length. We came to the conclusion that this was probably just what the kernel source sounded like.

2 hours ago by FeepingCreature

mplayer -demuxer rawaudio -rawaudio rate=48000 -format s16le -af volume=-20 /dev/sda

Warning, headphone users: may hurt your ears. Trust me on the volume lowering.

With 16 bit samples and (default) two channels, you can recognizeably hear small integer values in your left ear. :)

6 hours ago by gerdesj

Good skills.

It has never occurred to me to do that but it is actually quite an obvious thing to do when you "know" that everything is a file.

Any idea what the visual equivalent would be?

8 minutes ago by axiolite

> Any idea what the visual equivalent would be?

Perhaps:

head -c800 /dev/urandom > /dev/tty

Or:

mplayer -demuxer rawvideo -rawvideo w=80:h=60 /dev/urandom

5 hours ago by toast0

If you've got a framebuffer console, I think you can cat to /dev/fb ... Although pixels are less friendly than audio, it's kind of helpful for identifying patterns if you preprocess so everything is shades of one color, or a byte -> color map anyway.

6 hours ago by reshie

ffmpeg can point directly to the webcam under /dev/.

5 hours ago by anthk

Plan9's /dev/draw.

4 hours ago by qiqitori

for i in $(seq 1 10); do seq -120 1 120; seq 120 1 -120; done | aplay

It's for you.

8 hours ago by cogman10

The secret of *nix that people don't like accepting is the file approach is often the right approach.

Consider lowly embedded linux. You COULD dig down deep into the documentation of which register, which interrupt, which special memory address needs to be written to interact with the right ports on a embedded linux board. All while adding a bunch of safeguards and checks to make sure "Only you are doing this".

Or, as if often the case, you can simply find the right /dev/xxxx device and read from it or write to it.

9 times out of 10, you'd not suffer any negative consequences from using the /dev/xxx system as intended and you get the bonus ability of being able to interact with the outside world using programming languages other than C.

4 hours ago by PaulDavisThe1st

The file approach ignores anything that exists (at least in part) in the time domain.

Audio files are (for me) the canonical example. A text file has no inherent bit-rate. An audio file being handled without knowledge of (even just) its sample rate has its semantics distorted or destroyed.

There's an awful lot of things you can do with the file approach, and I love it. Cross into the time domain and try to retain the same approach, and I say you're making a serious mistake.

What's worse is when the actual programming APIs (as opposed to just redirecting stdout to /dev/dsp) also fail to model the time aspect, and encourage programmers to think that you can just shovel data at a device without any consequences for your software's properties (like latency).

an hour ago by dredmorbius

Many character devices do in fact have a bitrate.

6 hours ago by Denvercoder9

I don't think this has anything to do with the file approach per se, just with using an interface at a higher abstraction level.

7 hours ago by phamilton

My favorite version of this is reading from /dev/dsp will capture audio from the mic. I would cat this audio to /dev/dsp on another host over ssh in the school lab.

3 hours ago by kelnos

You used to be able to do that on Linux when its sound system was OSS ("Open Sound System", not "Open Source Software"), the same as FreeBSD uses today (I believe Linux still has an OSS compat layer). A long time ago the project lead was employed by a company to write support for some newer sound hardware, and decided to make those changes proprietary. The Linux folks decided to do something completely different, and we got ALSA, while some BSD folks decided to fork the last fully open source version of OSS and continue developing it.

The irony, of course, is that the proprietary version of OSS failed, and it ended up going open source again.

7 hours ago by nonameiguess

The point of CUPS and of server middleware in general like PulseAudio and what not is when multiple clients all want to send output streams to the same sink. Just sending the stream directly to a device with no middleman works fine provided 1) the stream is encoded in a way the device understands, and 2) no one else is trying to use it at the same time. For a shared network resource like a printer, unless you live alone and are the only user on your LAN, betting no one else is sending a job to the printer at the same time might be a rough bet.

Even when it works, there might be downsides, as some other comments are alluding to. The long print time one mentioned is likely because while you're lucky that your printer understands how to transcode pdf to ps in order to print a pdf, the onboard processor on the printer is much weaker than whatever you have on your computer. Also beware that if you're doing this on a radio network, I don't think netcat can encrypt the traffic. So don't be printing your credit card statements this way.

30 minutes ago by tonyedgecombe

>2) no one else is trying to use it at the same time.

Printers are fine with accepting jobs from multiple clients and have been for a long time. After all this is pretty much standard practice for any small office without a server.

6 hours ago by ChuckMcM

Hence the existence of lp(1), which at its simplest is just a queue that sends things to the network as they arrive.

7 hours ago by undefined

[deleted]

8 hours ago by corbet

FWIW, the Internet Printing Protocol (and IPP Everywhere in particular) make printer setup in CUPS far, far easier, but distributors seem reluctant to encourage it. I wrote about my experiences with IPP back in June (https://lwn.net/Articles/857502/). I expect to never have to hassle with printer drivers again...

6 hours ago by gerdesj

I own a HP MFP and for several years HPLIP generally worked for several to many months at a time, until it didn't. Me and the wiff both run Arch on our laptops (she doesn't know or care).

After a particularly rubbish time trying to get HPLIP working again after a pacman -Syu I did a literature search: Mr CUPS had deprecated everything apart from IPP Everywhere. So, I tried it out.

Me and the missus send docs to print and they get printed. I cannot remember the last failure (apart from running out of paper.) I also have toner levels monitored via Home Assistant.

I also have an office with several MFPs and inkjets, accessed via Windows (Server 2019) print queues. They are not so reliable. I often have to restart the Print Spooler service on our print server. To be fair, it is generally one queue that is at fault.

27 minutes ago by tonyedgecombe

>To be fair, it is generally one queue that is at fault.

Printer drivers run in process as well as the port monitor (for older printers). You might find the situation improves if you use an inbox driver (one that comes with Windows) and/or the standard port monitor.

an hour ago by abhgh

I read your article and finally got my Brother printer working on elementary OS! Thank you!

4 hours ago by askvictor

I thought that the whole point of CUPS was to provide an IPP service.

7 hours ago by merb

keep in mind not every printer has a good http stack, especially if the device never gets restarted this can be a problem.

3 hours ago by MonaroVXR

Didn't know about that, you got some examples?

6 hours ago by gerdesj

Probably true but why not turn it off and on again daily. While you are at it, you can restart your print queues regularly via a cronjob or Taskman.

There is no need to suffer if that will do the job.

Pragmatism is not the enemy of perfection.

8 hours ago by TacticalCoder

I used to do this at home all the time (from Linux though): networked printer with its own IP address and then good old netcat. I'd do it with PostScript files and send them to HP LaserJet 4M+: not only do these beauties speak PostScript natively, they can also be made to display the infamous "PC LOAD LETTER" message.

I'd try to find these printers used then I'd upgrade them: more RAM, more fonts, adding a network card inside the printer etc.

I still have several of these printers in a garage, some of them have printed more than 300 000 pages. They probably still work: some things were that good back then.

And, yup, there's something feeling magical when netcat'ing a .ps file (or another format) directly to the printer.

7 hours ago by jtvjan

I recently tried that with my Epson Ecotank, but instead of rendering the document, it just printed out the literal source code. It then held the paper halfway through the machine until I sent enough newlines.

I was only half disappointed.

24 minutes ago by tonyedgecombe

>It then held the paper halfway through the machine until I sent enough newlines.

That is what a form feed character is for (ASCII 0x0C).

8 hours ago by na85

How did you add network cards? Do some printers have PCI expansion slots?

7 hours ago by kindall

Proprietary, not PCI, but expansion slots, yes. On HPs it was called the MIO slot and later the EIO slot. If your printer came with a MIO card that only did serial and parallel, you could swap it for one that added networking.

an hour ago by jeffreygoesto

And if it stops working, try re-soldering it in an oven before throwing away. Some infamous batches had bad soldering problems that can be fixed. See i.e. [0]

[0] https://community.spiceworks.com/how_to/2077-how-to-bake-an-...

4 minutes ago by fogihujy

So, network equivalent of piping text to the parallel port?

2 hours ago by henearkr

I immediately tried it...

Aaand this is how I made my printer spit out dozens of garbage pages with just one to two lines of gibberish on each (the PDF source code, admirably giving up the page at each occurrence of the corresponding char)...

an hour ago by UberGuidoZ

Turns out that's the same result on Windows when using Ncat /shrug

3 minutes ago by henearkr

I'm on Linux (Arch) and I had no more luck with PS than with PDF...

My printer is a Brother HL-2270DW... seems to be quite a dumb one...

8 hours ago by dredmorbius

If you have a single host, and a single printer, or your printer itself is both network-enabled and can manage its own print spool, direct TCP/IP printing may indeed work for you.

The value of CUPS is that it enables the CUPS-serving computer to run as a print server. This means not only print drivers (document format support --- typically plain text, Postscript, and one or more PDL (printer definition languages) & PCL (Printer Control Language), but status on the printer, queue management, job control, and access control. Note that if your printer is generally available on your local WiFi network, you might want to give more thought to that last element.

If those are overkill for you and your printer Just Works with generated output, then yes, you can get by without the complexity.

Note that you can also often telnet directly to the printer port.

Be aware of what you're trading off, though, and whether or not you actually need what CUPS, or direct network access, offers.

8 hours ago by cbhl

The CUPS web front-end also has rough edges; Apple maintains CUPS these days and OS X now ships with the web interface on :631 disabled.

If you still need a print server, it can be well worth the extra $100 or so to buy a business-class printer with an IPP server in it, so that CUPS runs on a chip inside the printer instead of on a separate computer. (Generally anything that supports "Airprint" will do this, and also at the mid range you avoid the "printers whose ink cartridges are more expensive than the printer" zone.)

4 hours ago by BearOso

> Apple maintains CUPS these days

Apple never really maintained CUPS. They hired the author, Michael Sweet, and he pretty much served as the printing team. He left Apple a couple years ago, and basically stalled their printing department.

He’s recently become head of the Printer Working Group, and they’re all pushing IPP Everywhere towards greater adoption. It’s a laudable effort.

Daily digest email

Get a daily email with the the top stories from Hacker News. No spam, unsubscribe at any time.