c51f2c8
diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c
c51f2c8
index 24dc7df..e393931 100644
c51f2c8
--- a/converter/other/pnmtops.c
c51f2c8
+++ b/converter/other/pnmtops.c
c51f2c8
@@ -1909,6 +1909,7 @@ convertPage(FILE *       const ifP,
c51f2c8
         /* The file stream which is the head of the filter chain; we write to
c51f2c8
            this and filtered stuff comes out the other end.
c51f2c8
         */
c51f2c8
+    FILE * filterChainOfP;
c51f2c8
 
c51f2c8
     pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));
c51f2c8
 
c51f2c8
@@ -1951,7 +1952,11 @@ convertPage(FILE *       const ifP,
c51f2c8
     initOutputEncoder(&oe, inpam.width, bitsPerSample,
c51f2c8
                       rle, flate, ascii85, psFilter);
c51f2c8
 
c51f2c8
-    spawnFilters(stdout, &oe, &feedFileP, filterPidList);
c51f2c8
+    fflush(stdout);
c51f2c8
+    filterChainOfP = fdopen(dup(fileno(stdout)), "w");
c51f2c8
+        /* spawnFilters() closes this. See FILE MANAGEMENT above */
c51f2c8
+
c51f2c8
+    spawnFilters(filterChainOfP, &oe, &feedFileP, filterPidList);
c51f2c8
  
c51f2c8
     convertRaster(&inpam, bitsPerSample, psFilter, feedFileP);
c51f2c8