popen()

Stephen M. Dunn cs4g6ag at maccs.dcss.mcmaster.ca
Sun Mar 4 04:22:31 AEST 1990


In article <1503 at loria.crin.fr> anigbogu at loria.crin.fr (Julian Anigbogu) writes:
$Can some kind soul point me to where I can get a PC implementation of
$the Unix C popen() /* for handle to a pipe */. I manipulate huge
$rasterfiles(from a scanner) on a Sun and I adopted the policy of
$compressing all files to save disk space. I open them with
$popen("uncompress -c filename","r") so that they remain compressed on
$disk. 
$ I now need to port the programs to DOS and to my chagrin my regular
$compiler doesn't implement a pipe open.

   This isn't a problem with your compiler ... it's just that Unix is a
multi-tasking operating system which can run one program and have its output
piped directly into another program, while DOS is single-tasking and
cannot do this.  DOS's idea of a pipe is as follows:

-run program 1 with its stdout redirected to some file
-run program 2 with its stdin redirected from that file
-delete the temporary file

and the only part of DOS that has any idea of how to do a pipe is the command
interpreter in any case.

   You'll have to implement it yourself by doing the same sort of
thing yourself:  write a function popen that does:

-come up with a temporary file name (there should be a call in your
 library to do this; it's a standard DOS function in DOS 3 and up.
-spawn or exec or system your uncompress utility with redirection of stdout
 (how you handle this depends on which call you use)
-fopen the temporary file and return that handle

and a corresponding close that does:

-close the file
-delete the temporary file

   And, of course, this will take up disk space while your program is
running.
-- 
Stephen M. Dunn                               cs4g6ag at maccs.dcss.mcmaster.ca
          <std_disclaimer.h> = "\nI'm only an undergraduate!!!\n";
****************************************************************************
               I Think I'm Going Bald - Caress of Steel, Rush



More information about the Comp.lang.c mailing list