home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / posix / stdio / popen.txh < prev   
Encoding:
Text File  |  1995-07-17  |  1.9 KB  |  70 lines

  1. @node popen, unix
  2. @subheading Syntax
  3.  
  4. @example
  5. #include <stdio.h>
  6.  
  7. FILE *popen(const char *program, const char *mode);
  8. @end example
  9.  
  10. @subheading Description
  11.  
  12. This function executes the named @code{program} and attaches either its
  13. input stream or its output stream to the returned file.  While the file
  14. is open, the calling program can write to the program (if the program
  15. was open for writing) or read the program's output (if the program was
  16. opened for reading).  When the program is done, or if you have no more
  17. input for it, pass the file pointer to @code{pclose} (@pxref{pclose}),
  18. which terminates the program. 
  19.  
  20. Since MS-DOS does not support multitasking, this function actually runs
  21. the entire program when the program is opened for reading, and stores
  22. the output in a temporary file.  @code{pclose} then removes that file. 
  23. Similarly, when you open a program for writing, a temp file holds the
  24. data and @code{pclose} runs the entire program.
  25.  
  26. The @var{mode} is the same as for @code{fopen} (@pxref{fopen}). 
  27.  
  28. @subheading Return Value
  29.  
  30. An open file which can be used to read the program's output or write to
  31. the program's input. 
  32.  
  33. @subheading Example
  34.  
  35. @example
  36. FILE *p = popen("dir", "r");
  37. read_program(p);
  38. pclose(p);
  39. @end example
  40.  
  41. @c ----------------------------------------------------------------------
  42. @node pclose, unix
  43. @subheading Syntax
  44.  
  45. @example
  46. #include <stdio.h>
  47.  
  48. int pclose(FILE *pipe);
  49. @end example
  50.  
  51. @subheading Description
  52.  
  53. This function closes a pipe opened with @code{popen} (@pxref{popen}). 
  54. Note that since MS-DOS is not multitasking, this function will actually
  55. run the program specified in @code{popen} if the pipe was opened for
  56. writing. 
  57.  
  58. @subheading Return Value
  59.  
  60. Zero on success, nonzero on failure.
  61.  
  62. @subheading Example
  63.  
  64. @example
  65. FILE *f = popen("sort", "w");
  66. write_to_pipe(f);
  67. pclose(f);
  68. @end example
  69.  
  70.