pipes and commands

Bernhard Herzog herzog at online.de
Sun Oct 31 18:11:48 EST 1999


Gregor Zych <zych at pool.informatik.rwth-aachen.de> writes:

> Bernhard Herzog <herzog at online.de> writes:
> >
> > gs_command = ('gs -sDEVICE=ppmraw -r%(resolution)d -dNOPAUSE -dSAFER -q'
> > 	      ' -sOutputFile=%(temp)s -g%(width)dx%(height)d'
>                              ^^^^^^^^ This is fine until you send this 
> stuff to stdout. Either Python doesn't realize that gs is ready OR gs
> doesn't send the correct exit code.
> > 	      ' -c %(offx)f %(offy)f translate'
> > 	      ' /oldshowpage /showpage load def /showpage \'{}\' def '
> > 	      ' -f%(filename)s -c oldshowpage quit')

Well, it also works for me with this version, where the gs output is
piped through pnminvert:

gs_command = ('gs -sDEVICE=ppmraw -r%(resolution)d -dNOPAUSE -dSAFER -q'
	      ' -sOutputFile=- -g%(width)dx%(height)d'
	      ' -c %(offx)f %(offy)f translate'
	      ' /oldshowpage /showpage load def /showpage \'{}\' def '
	      ' -f%(filename)s -c oldshowpage quit | pnminvert > %(temp)s')

even a stripped down version that generates pbm instead of ppm works:

gs_command = ('gs -sDEVICE=pbmraw -r%(resolution)d -dNOPAUSE -dSAFER -q'
	      ' -sOutputFile=- -g%(width)dx%(height)d'
	      ' %(filename)s quit.ps | pnminvert  > %(temp)s')

This second version only works if the inputfile executes showpage
exactly once. Could it be that your ps files have more than one page? In
that case piping the gs output through some pbm-filters behaves as you
describe, that is, the output file is created correctly but os.system
never finishes. Interestingly enough, when the same commandline is
execute in an xterm with bash, it seems to work properly and finishes.


-- 
Bernhard Herzog	  | Sketch, a drawing program for Unix
herzog at online.de  | http://www.online.de/home/sketch/




More information about the Python-list mailing list