popen, pclose, and compress

popen, pclose, and compress

Post by Larry Rose » Sat, 11 May 1996 04:00:00



I'm working on some code that writes a large data string (array of bytes)
to a compressed file the following way:

FILE *pfd;
int iNumWrote;
char buffer[12000];
int iBufLen = 12000;

. . . (fill in buffer with 12000 bytes) . . .

pfd = popen ("compress > myfile", "w");
iNumWrote = fwrite (buffer, sizeof(char), iBufLen, pfd);
pclose(pfd);

My actual code is slightly different and has checks return value of popen
and pclose.

This seemed to work fine on my IRIX 5.3.  Then one day I got the following
error: pclose would return with value < 0 and errno would be set:
        errno = 10 (No child processes)

Meanwhile, the compressed files were created with no problem.  Apparently
the compress process finished before pclose was executed?  So I ignore this
error.  Now when the code is run on different UNIX platforms (ie. HP, Sun, IBM...)
other, different error's are raised which I haven't pinpointed yet, but are
probably related.

Has anyone dealt with this type of problem?

What happens when the buffer size exceeds the system's pipe buffer size?

- + - + - + - + - +- + - + - + - + - +- + - + - + - + - +- + - + - + - + - +
Larry Rosen

 
 
 

1. popen, pclose, and compress

I'm working on some code that writes a large data string (array of bytes)
to a compressed file the following way:

FILE *pfd;
int iNumWrote;
char buffer[12000];
int iBufLen = 12000;

. . . (fill in buffer with 12000 bytes) . . .

pfd = popen ("compress > myfile", "w");
iNumWrote = fwrite (buffer, sizeof(char), iBufLen, pfd);
pclose(pfd);

My actual code is slightly different and has checks return value of popen
and pclose.

This seemed to work fine on my IRIX 5.3.  Then one day I got the following
error: pclose would return with value < 0 and errno would be set:
        errno = 10 (No child processes)

Meanwhile, the compressed files were created with no problem.  Apparently
the compress process finished before pclose was executed?  So I ignore this
error.  Now when the code is run on different UNIX platforms (ie. HP, Sun,
IBM...)
other, different error's are raised which I haven't pinpointed yet, but are
probably related.

Larry Rosen
Hughes STX

2. Decimal to Hex ?

3. compressing on the fly: father process seems to end before popened compress

4. Help with rcsmerge

5. popen()/pclose() and SIGCHLD

6. In Kppp under KDE, the modem dials and stays up OK, but ...

7. popen/pclose

8. Anonymous ftp security hole

9. popen/pclose question

10. Why doesn't pclose free the memory the popen allocated ?

11. popen/pclose

12. Two pipes using popen()/pclose() ?

13. trivial popen/pclose vs. fork/execlp/wait question