Merge pull request #1523 from radarhere/pilprint

Added subprocess.Popen to pilprint script
This commit is contained in:
wiredfool 2015-11-18 09:34:11 +00:00
commit 46b9bbde87

17
Scripts/pilprint.py Normal file → Executable file
View File

@ -15,6 +15,7 @@ from __future__ import print_function
import getopt
import os
import sys
import subprocess
VERSION = "pilprint 0.3/2003-05-05"
@ -46,8 +47,8 @@ except getopt.error as v:
print(v)
sys.exit(1)
printer = None # print to stdout
monochrome = 1 # reduce file size for most common case
printerArgs = [] # print to stdout
monochrome = 1 # reduce file size for most common case
for o, a in opt:
if o == "-d":
@ -60,10 +61,10 @@ for o, a in opt:
monochrome = 0
elif o == "-p":
# default printer channel
printer = "lpr"
printerArgs = ["lpr"]
elif o == "-P":
# printer channel
printer = "lpr -P%s" % a
printerArgs = ["lpr","-P%s" % a]
for filepath in argv:
try:
@ -76,8 +77,9 @@ for filepath in argv:
im.draft("L", im.size)
im = im.convert("L")
if printer:
fp = os.popen(printer, "w")
if printerArgs:
p = subprocess.Popen(printerArgs, stdin=subprocess.PIPE)
fp = p.stdin
else:
fp = sys.stdout
@ -91,6 +93,9 @@ for filepath in argv:
ps.image(letter, im)
ps.end_document()
if printerArgs:
fp.close()
except:
print("cannot print image", end=' ')
print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))