Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Inside of a script I send a certain file to print using the lpr command on an user-selected printer.

The list of the printers, from which the user selects the one to use, I get using the lpstat -a command and then considering everything before the first space as the name of the printer.

This works but relies heavily on the specific output format of the lpstat -a command. I'm afraid that in the future (or now on different distributions) if the output format changes it will break the script.

So, is there a way to get the names of all the installed printers in a way that is safer than the one I'm using?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

CUPS is (partly) GPL-licensed, so you could just grab the source of lpstat(1) and create your own little (GPL-licensed) give-my-list-of-printers-program that will never change the way it outputs data.

(1) It's in cups-XX/cups/systemv/lpstat.c, I just don't understand the versions numbers there.

share|improve this answer
    
This is a good solution, but unfortunately the "script" is actually a Java applet, i cannot change the target system or install new stuff on it. It's related to this question: stackoverflow.com/questions/13743738/… And i thought that using lpr instead was a good idea –  Enoon Dec 9 '12 at 20:15
    
Hmm, there's CUPS4J, which might or might not be an option... it can "get printers objects from a CUPS server that can be used to print and monitor jobs" –  sr_ Dec 10 '12 at 8:12
    
This seems an interisting solution, thanks! –  Enoon Dec 10 '12 at 12:23

I also need a list of printers and had the same concern. Following the above suggestion I checked the source of lpstat.c . I was expecting it to be a suid so it could read "/etc/cups/printers.conf" . I now realise it does not do this.

Instead it sends a HTTP POST request to localhost:631 where cupsd runs. The request is of the form Content-Type: application/ipp and things such as requested-attributes auth-info-required . The reason not to be more specific is that it uses a non-standard encoding (see: http://en.wikipedia.org/wiki/Internet_Printing_Protocol) ... so I suspect actually parsing the output of lpstat -a is actually cleaner.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.