Index: pykota/trunk/pykota/accounters/stupid.py
===================================================================
--- pykota/trunk/pykota/accounters/stupid.py (revision 977)
+++ pykota/trunk/pykota/accounters/stupid.py (revision 1000)
@@ -21,4 +21,8 @@
 #
 # $Log$
+# Revision 1.3  2003/05/27 23:00:21  jalet
+# Big rewrite of external accounting methods.
+# Should work well now.
+#
 # Revision 1.2  2003/04/30 13:40:47  jalet
 # Small fix
@@ -44,5 +48,5 @@
         
         # get the job size    
-        jobsize = self.getJobSize()
+        jobsize = self.getJobSize() * self.filter.copies
             
         # get last job information for this printer
@@ -86,6 +90,5 @@
         pagecount = 0
         for line in infile.xreadlines() :
-            if line.startswith("showpage") :
-                pagecount += 1
+            pagecount += line.count("showpage")
             if temporary is not None :    
                 temporary.write(line)    
Index: pykota/trunk/pykota/accounters/external.py
===================================================================
--- pykota/trunk/pykota/accounters/external.py (revision 995)
+++ pykota/trunk/pykota/accounters/external.py (revision 1000)
@@ -21,4 +21,8 @@
 #
 # $Log$
+# Revision 1.3  2003/05/27 23:00:21  jalet
+# Big rewrite of external accounting methods.
+# Should work well now.
+#
 # Revision 1.2  2003/05/13 13:54:20  jalet
 # Better handling of broken pipes
@@ -42,6 +46,6 @@
            The command must print the job size on its standard output and exit successfully.
         """
-        # get the job size    
-        jobsize = self.getJobSize()
+        # get the job size, which is real job size * number of copies.
+        jobsize = self.getJobSize() * self.filter.copies
             
         # get last job information for this printer
@@ -81,32 +85,45 @@
             
         # launches external accounter
+        infilename = tempfile.mktemp()
+        outfilename = tempfile.mktemp()
+        errfilename = tempfile.mktemp()
+        
         try :
-            process = popen2.Popen3("%s" % self.arguments)
-        
             # feed it with our data
+            fakeinput = open(infilename, "wb")
             data = infile.read(256*1024)    
             while data :
-                process.tochild.write(data)
-                temporary.write(data)
+                fakeinput.write(data)
+                if temporary is not None :
+                    temporary.write(data)
                 data = infile.read(256*1024)
-            process.tochild.close()
+            fakeinput.close()
         
-            # wait for child process to exit (or die)
-            retcode = process.wait()
+            # launches child process
+            command = "%s <%s >%s 2>%s" % (self.arguments, infilename, outfilename, errfilename)
+            o = open("/tmp/comm", "w")
+            o.write("%s\n" % command)
+            o.close()
+            retcode = os.system(command)
             
             # check exit status
-            if os.WIFEXITED(retcode) and not os.WEXITSTATUS(retcode) :
+            if (os.WIFEXITED(retcode) and not os.WEXITSTATUS(retcode)) or os.stat(errfilename) :
                 # tries to extract the job size from the external accounter's
                 # standard output
+                childoutput = open(outfilename, "r")
                 try :
-                    pagecount = int(process.fromchild.readline().strip())
+                    pagecount = int(childoutput.readline().strip())
                 except (AttributeError, ValueError) :
                     self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments)
                     pagecount = 0
+                childoutput.close()    
             else :
                 self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % self.arguments)
                 pagecount = 0
-            process.fromchild.close()    
+            os.remove(infilename)
+            os.remove(outfilename)
+            os.remove(errfilename)
         except IOError, msg :    
+            # TODO : temporary files may remain on the filesystem...
             msg = "%s : %s" % (self.arguments, msg) 
             self.filter.logger.log_message(_("Unable to compute job size with external accounter %s") % msg)
