EDIT: I forgot to make it clear I'm using python and pycups. The code is python but I shouldn't have thought that was enough.

I've dug through the cups documentation a few times and couldn't find anything to do this. Is there any message that gets returned on a successful print that can be captured?

For example in this code:

import os
import cups

conn = cups.Connection()

f = open('testreceipt.txt', 'w')
printer_returns = conn.printFile('EPSON_TM-P2.01', 'testreceipt.txt', 'test', {})
print printer_returns

All that printer_returns gets assigned appears to be the print job id (208,209,...,n). This occurs whether or not a printer is connected, and thus can't be relied upon for confirmation.

In this case the target printer is a receipt printer attached by a serial->usb cable into a raspberry pi running raspbian.

I've considered monitoring the cups log file for successful prints but that seems like a bad way to go about it.

I'm not sure where else to go with finding a solution so if anyone has thoughts, please share them.

  • If the printer is not connected, CUPS should keep it in the queue unti it is available. – jordanm Jan 29 '13 at 2:48
  • 1
    Define "successful print". A job could be in the queue indefinitely, is that "successful" when printed, even if there was a delay? There are lots of things to watch out for here. It is better to narrow down to "do something when printed" rather than "do something when successful", which is largely ambiguous. – Chris Down Jan 29 '13 at 3:08
  • Sorry! This is a good point. In this case a successful print is a complete physical print and not just a queued job. I need to make sure the print occurred or return an error. – Jeff H. Jan 31 '13 at 1:04

I'm using getJobs to verify, if the jobs was sent to the printer.

printid = conn.printFile('EPSON_TM-P2.01', 'testreceipt.txt', 'test', {})
while conn.getJobs().get(printid, None) is not None:

After sending the document, check the cupsLastErrorString. If it's null, you should be good. Also, most of the functions should tell you if it failed, as they return an integer.

Found here


This is what I finally ended up doing. The printFile() function returns the print id which cups uses, while the current print queue through the commandline is accessible via lpstat. I think it's a bit messy but it's good enough for my needs right now. Thanks for the help everyone, you all nudged me in the appropriate direction.

20 printid = conn.printFile('EPSON_TM-P2.01', 'testreceipt.txt', 'test', {})
22 stop = 0
23 TIMEOUT = 60
25 while str(subprocess.check_output(["lpstat"])).find(str(printid)) > 0 and    stop < TIMEOUT:
26     stop+= 1
27     time.sleep(1)
28 if stop < TIMEOUT:
29     print "PRINT SUCCESS"
30 else:
31     print "PRINT FAILURE"

I believe the equivalent in pycups is the IPPError class (note the try / except example code), since the cupsLastError* functions in cups returns the IPP error codes.

Checking the status code of a subprocess should also work, but seems like unnecessary overhead if pycups will give you the code directly.


You could wait until



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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