Skip to content

Instantly share code, notes, and snippets.

@carsonmcdonald
Last active July 29, 2018 06:13
Show Gist options
  • Save carsonmcdonald/4586165 to your computer and use it in GitHub Desktop.
Save carsonmcdonald/4586165 to your computer and use it in GitHub Desktop.
Quick python script to print to a file with cups.
#!/usr/bin/python
# sudo lpadmin -p printer-name-here -E -v socket://localhost:12000 -m raw
import socket
fpsock = socket.socket()
fpsock.bind(('127.0.0.1', 12000))
fpsock.listen(5)
while True:
(clientsock, addr) = fpsock.accept()
morebuffer = True
buffer = clientsock.recv(4096)
while morebuffer:
nb = clientsock.recv(4096)
if not nb:
morebuffer = False
buffer += nb
outfile = open('/tmp/fakeprinter.out', 'a')
outfile.write(buffer)
outfile.close()
clientsock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment