Last active
July 29, 2018 06:13
-
-
Save carsonmcdonald/4586165 to your computer and use it in GitHub Desktop.
Quick python script to print to a file with cups.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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