FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #1523 from radarhere/pilprint · v-python/Pillow@46b9bbd · GitHub

Repository navigation

Commit 46b9bbd

Browse files
committed
Merge pull request python-pillow#1523 from radarhere/pilprint
Added subprocess.Popen to pilprint script
2 parents b07872b + 7d8d9e3 commit 46b9bbd

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎Scripts/pilprint.py‎

100644100755
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import getopt
1616
import os
1717
import sys
18+
import subprocess
1819

1920
VERSION = "pilprint 0.3/2003-05-05"
2021

@@ -46,8 +47,8 @@ def description(filepath, image):
4647
print(v)
4748
sys.exit(1)
4849

49-
printer = None # print to stdout
50-
monochrome = 1 # reduce file size for most common case
50+
printerArgs = [] # print to stdout
51+
monochrome = 1 # reduce file size for most common case
5152

5253
for o, a in opt:
5354
if o == "-d":
@@ -60,10 +61,10 @@ def description(filepath, image):
6061
monochrome = 0
6162
elif o == "-p":
6263
# default printer channel
63-
printer = "lpr"
64+
printerArgs = ["lpr"]
6465
elif o == "-P":
6566
# printer channel
66-
printer = "lpr -P%s" % a
67+
printerArgs = ["lpr","-P%s" % a]
6768

6869
for filepath in argv:
6970
try:
@@ -76,8 +77,9 @@ def description(filepath, image):
7677
im.draft("L", im.size)
7778
im = im.convert("L")
7879

79-
if printer:
80-
fp = os.popen(printer, "w")
80+
if printerArgs:
81+
p = subprocess.Popen(printerArgs, stdin=subprocess.PIPE)
82+
fp = p.stdin
8183
else:
8284
fp = sys.stdout
8385

@@ -91,6 +93,9 @@ def description(filepath, image):
9193
ps.image(letter, im)
9294
ps.end_document()
9395

96+
if printerArgs:
97+
fp.close()
98+
9499
except:
95100
print("cannot print image", end=' ')
96101
print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL