using os.system and ps2pdf
Jeffery D. Collins
jcollins at boulder.net
Wed Jun 20 20:52:00 EDT 2001
On Thu, Jun 21, 2001 at 12:19:49AM +0000, iddwb wrote:
> 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
ps.close()
> print "ps2pdf %s %s" % (psf, pdf)
> os.system("ps2pdf %s %s" % (psf, pdf))
>
> David Bear
> College of Public Programs/ASU
--
Jeffery Collins (http://www.boulder.net/~jcollins)
More information about the Python-list
mailing list