Index: pkpgcounter/trunk/pkpgpdls/tiff.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/tiff.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/tiff.py (revision 492)
@@ -32,5 +32,5 @@
 class Parser(pdlparser.PDLParser) :
     """A parser for TIFF documents."""
-    totiffcommands = [ "cat >%(fname)s" ]
+    totiffcommands = [ '/bin/cp "%(infname)s" "%(outfname)s"' ]
     def isValid(self) :        
         """Returns True if data is TIFF, else False."""
Index: pkpgcounter/trunk/pkpgpdls/pdlparser.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/pdlparser.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/pdlparser.py (revision 492)
@@ -94,50 +94,27 @@
         raise RuntimeError, "Not implemented !"
         
-    def convertToTiffMultiPage24NC(self, fname, dpi) :
+    def convertToTiffMultiPage24NC(self, outfname, dpi) :
         """Converts the input file to TIFF format, X dpi, 24 bits per pixel, uncompressed.
-           Writes TIFF datas to the file named by fname.
+           Writes TIFF datas to the file named by outfname.
         """   
         if self.totiffcommands :
-            infile = open(self.filename, "rb")
-            try :
-                for totiffcommand in self.totiffcommands :
-                    infile.seek(0)
-                    error = False
-                    commandline = totiffcommand % locals()
-                    child = popen2.Popen4(commandline)
-                    try :
-                        try :
-                            data = infile.read(MEGABYTE)    
-                            while data :
-                                child.tochild.write(data)
-                                child.tochild.flush()
-                                data = infile.read(MEGABYTE)
-                        except (IOError, OSError) :    
-                            error = True
-                    finally :    
-                        child.tochild.close()    
-                        dummy = child.fromchild.read()
-                        child.fromchild.close()
-                        
-                    try :
-                        status = child.wait()
-                    except OSError :    
+            infname = self.filename
+            for totiffcommand in self.totiffcommands :
+                error = False
+                commandline = totiffcommand % locals()
+                # self.logdebug("Executing '%s'" % commandline)
+                status = os.system(commandline)
+                if os.WIFEXITED(status) :
+                    if os.WEXITSTATUS(status) :
                         error = True
-                    else :    
-                        if os.WIFEXITED(status) :
-                            if os.WEXITSTATUS(status) :
-                                error = True
-                        else :        
-                            error = True
-                        
-                    if not os.path.exists(fname) :
-                        error = True
-                    elif not os.stat(fname).st_size :
-                        error = True
-                    else :        
-                        break       # Conversion worked fine it seems.
-                    self.logdebug("Command failed : %s" % repr(commandline))
-            finally :        
-                infile.close()
+                else :        
+                    error = True
+                if not os.path.exists(outfname) :
+                    error = True
+                elif not os.stat(outfname).st_size :
+                    error = True
+                else :        
+                    break       # Conversion worked fine it seems.
+                sys.stderr.write("Command failed : %s\n" % repr(commandline))
             if error :
                 raise PDLParserError, "Problem during conversion to TIFF."
Index: pkpgcounter/trunk/pkpgpdls/inkcoverage.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/inkcoverage.py (revision 463)
+++ pkpgcounter/trunk/pkpgpdls/inkcoverage.py (revision 492)
@@ -116,5 +116,5 @@
     else :    
         try :
-            while 1 :
+            while True :
                 nbpixels = image.size[0] * image.size[1]
                 result.append(computation(image, nbpixels))
Index: pkpgcounter/trunk/pkpgpdls/plain.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/plain.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/plain.py (revision 492)
@@ -28,6 +28,6 @@
 class Parser(pdlparser.PDLParser) :
     """A parser for plain text documents."""
-    totiffcommands = [ 'enscript --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',
-                       'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',
+    totiffcommands = [ 'enscript --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -',
+                       'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -',
                      ]  
     openmode = "rU"                 
Index: pkpgcounter/trunk/pkpgpdls/pdf.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/pdf.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/pdf.py (revision 492)
@@ -43,5 +43,5 @@
 class Parser(pdlparser.PDLParser) :
     """A parser for PDF documents."""
-    totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ]
+    totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" "%(infname)s"' ]
     openmode = "rU"
     def isValid(self) :    
Index: pkpgcounter/trunk/pkpgpdls/postscript.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/postscript.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/postscript.py (revision 492)
@@ -33,5 +33,5 @@
 class Parser(pdlparser.PDLParser) :
     """A parser for PostScript documents."""
-    totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ]
+    totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" "%(infname)s"' ]
     openmode = "rU"
     def isValid(self) :    
Index: pkpgcounter/trunk/pkpgpdls/pcl345.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/pcl345.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/pcl345.py (revision 492)
@@ -39,6 +39,6 @@
 class Parser(pdlparser.PDLParser) :
     """A parser for PCL3, PCL4, PCL5 documents."""
-    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r%(dpi)i -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -', 
-                       'pcl6 -sDEVICE=pswrite -r%(dpi)i -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',
+    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -', 
+                       'pcl6 -sDEVICE=pswrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -',
                      ]
     mediasizes = {  # ESC&l####A
Index: pkpgcounter/trunk/pkpgpdls/pclxl.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/pclxl.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/pclxl.py (revision 492)
@@ -33,6 +33,6 @@
 class Parser(pdlparser.PDLParser) :
     """A parser for PCLXL (aka PCL6) documents."""
-    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r%(dpi)i -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -', 
-                       'pcl6 -sDEVICE=pswrite -r%(dpi)i -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',
+    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 
+                       'pcl6 -sDEVICE=pswrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -',
                      ]
     mediasizes = { 
Index: pkpgcounter/trunk/pkpgpdls/dvi.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/dvi.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/dvi.py (revision 492)
@@ -32,5 +32,5 @@
 class Parser(pdlparser.PDLParser) :
     """A parser for DVI documents."""
-    totiffcommands = [ 'cat >%(fname)s && dvips -q -o - %(fname)s | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ]
+    totiffcommands = [ 'dvips -q -o - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -' ]
     def isValid(self) :        
         """Returns True if data is DVI, else False."""
Index: pkpgcounter/trunk/pkpgpdls/analyzer.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/analyzer.py (revision 491)
+++ pkpgcounter/trunk/pkpgpdls/analyzer.py (revision 492)
@@ -82,9 +82,17 @@
             try :
                 pdlhandler = self.detectPDLHandler()
-                pdlhandler.convertToTiffMultiPage24NC(self.filename, self.options.resolution)
-                result = inkcoverage.getInkCoverage(self.filename, cspace)
+                (handle, filename) = tempfile.mkstemp(".tmp", "pkpgcounter")
+                os.close(handle)
+                try :
+                    pdlhandler.convertToTiffMultiPage24NC(filename, self.options.resolution)
+                    result = inkcoverage.getInkCoverage(filename, cspace)
+                finally :    
+                    try :
+                        os.remove(filename)
+                    except OSError :    
+                        sys.stderr.write("Problem while trying to remove temporary file %s\n" % filename)
             except pdlparser.PDLParserError, msg :    
                 raise pdlparser.PDLParserError, "Unknown file format for %s (%s)" % (self.filename, msg)
-        finally :    
+        finally :
             self.closeFile()
         return result
