home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / lsqrft15.zip / popen.c < prev    next >
Text File  |  1993-12-11  |  932b  |  48 lines

  1. #include <stdio.h>
  2. #include <process.h>
  3. #define INCL_DOS
  4. #include <os2.h>
  5. #include <io.h>
  6.  
  7. /*courtesy of Roger Fearick */
  8. FILE *popen(char *file, char mode[5]){
  9.  
  10. HFILE    hWritePipe ;
  11. HFILE    hR2 ;
  12. int      hR, save ;
  13. FILE     *gnu ;
  14. int error;
  15.     
  16. /* retain copy of old file descriptor */  
  17. save = _dup( 0 ) ;         
  18.  
  19. /* create pipe */
  20. DosCreatePipe( &hR2, &hWritePipe, 1024 ) ;
  21.  
  22. /* make '0' refer to pipe */
  23. hR = 0 ;                   
  24. _dup2( hR2, hR ) ;
  25.  
  26. /* start gnuplot */
  27. error = _spawnlp( P_NOWAIT, "gnuplot.exe", "gnuplot.exe", NULL ) ;
  28. if(error == -1) printf("error in _spawnl()\n");
  29.  
  30. /* open a file handle to write to gnuplot */
  31. gnu = _fdopen( hWritePipe, "w" ) ;
  32. _dup2( save, 0 ) ;        /* restore original stdin */
  33.  
  34. return gnu;
  35. }
  36.  
  37. void pclose(FILE *stream){
  38.  
  39. }
  40.  
  41. void sleep(int num){
  42. unsigned long milliseconds;
  43.  
  44. milliseconds = 1000 * num;
  45. DosSleep(milliseconds);
  46. }
  47.  
  48.