using os.system and ps2pdf
iddwb
iddwb at imap1.asu.edu
Wed Jun 20 20:19:49 EDT 2001
Problem. I need to read stdin, and convert it to pdf. Luckily, stdin
will give me postscript. So, I thought I simple script would work.
Invoking the ps2pdf program manually works fine to create the
pdf. Unfortunately, the following code doesn't allow ps2pdf to do its
work fully, It creates an empty pdf. Is there a better way to call an
external program than os.system? Alternatively, could reading stdin be
dropping something?
any advice would be appreciated.
#!/usr/local/bin/python
import os, sys, tempfile
if __name__ == '__main__':
psf = tempfile.mktemp("psf")
pdf = tempfile.mktemp("pdf")
ps = open(psf, "w")
ps.write(sys.stdin.read())
ps.close
print "ps2pdf %s %s" % (psf, pdf)
os.system("ps2pdf %s %s" % (psf, pdf))
David Bear
College of Public Programs/ASU
More information about the Python-list
mailing list