pipes and commands

Bernhard Herzog herzog at online.de
Sat Oct 30 13:53:27 EDT 1999


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

> > Gregor Zych <zych at pool.informatik.rwth-aachen.de> writes:
> > 
> > > Hi!
> > > How can I get many commands connected with pipes executed. I try
> > > 
> > > startexe = 'gs -q -dNOPAUSE -sDEVICE=pbmraw -r600x600 -sOutputFile=- '+pfad+'/'+name+'.eps quit.ps | pnmcut 610 982 4023 5483 | pnmtotiff - > '+pfad+'/'+name+'.tif'
> > > os.system(startexe)
> > > 
> > > but the system just waits for ever until I interrupt it, although it
> > > gets the final file written correctly.

The first thing I do when I have problems with os.system() is to check
whether the command works properly when run in an interactive shell.
Have you tried that?

FWIW, I use the code below in Sketch to render preview images for
embedded eps files. Apart from some postscript trickery to make sure the
contents of the BoundingBox are positioned correctly and that showpage
is executed exactly once, the only difference I can see in my code is
that I use -c quit instead of quit.ps.

To make sure that piping the output through some ppm-utility isn't the
problem, I've just checked it by piping it through pnminvert and it
worked as expected.

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

def render_preview(filename, startx, starty, width, height, resolution = None):
    import tempfile
    temp = tempfile.mktemp()

    try:
        if resolution is None:
            resolution = config.preferences.eps_preview_resolution
        factor = resolution / 72.0
        width = int(math.ceil(width * factor))
        height = int(math.ceil(height * factor))
	offx = -startx
	offy = -starty
	os.system(gs_command % locals())

	image = Image.open(temp)
	image.load()
	return image
    finally:
	try:
	    os.unlink(temp)
	except:
	    pass



-- 
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