Module to print to lpd?
Jeff Bauer
jbauer at rubic.com
Wed Aug 30 11:56:00 EDT 2000
Grant Edwards wrote:
> Does anybody have any Python code to print
> to a bsd lpd daemon?
>
> You know -- open a TCP connection to hostname:515 and
> send the right stuff to get something printed?
Grant,
Here's a teaser function to get the lpd daemon status.
-Jeff
#!/usr/bin/env python
# lpstat.py - jbauer at rubic.com
import os, socket, sys
def lpstat(host, printer):
s = socket.gethostbyname(host)
fd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
fd.bind(('0.0.0.0', 855))
fd.connect((s, 515))
str = '\003%s\n' % printer
fd.send(str, 0)
return fd.recv(2048, 0)
if __name__ == '__main__':
usage = "usage: %s host printer" % os.path.basename(sys.argv[0])
if len(sys.argv) < 3:
print usage
else:
print lpstat(sys.argv[1], sys.argv[2])
More information about the Python-list
mailing list