home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19237 < prev    next >
Encoding:
Internet Message Format  |  1993-01-05  |  1.7 KB

  1. Path: sparky!uunet!mcsun!sun4nl!and!jos
  2. From: jos@and.nl (Jos Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Piping and return code again! Please help !!!
  5. Message-ID: <4289@dozo.and.nl>
  6. Date: 5 Jan 93 09:11:37 GMT
  7. References: <1993Jan4.212844.1@woods.ulowell.edu>
  8. Organization: AND Software BV Rotterdam
  9. Lines: 34
  10.  
  11. In article <1993Jan4.212844.1@woods.ulowell.edu> tongb@woods.ulowell.edu writes:
  12. |
  13. |Please help!!!!!
  14. |
  15. |How do we make piping works in C for a DOS system?
  16. |
  17. |Dos offers:
  18. |
  19. |c:> program1 | program2
  20. |
  21. |to pass the output of the program1 as the input of the program2.  Now if we
  22. |have a C var declared as char mystring[] = "this is a string";
  23. |
  24. |and we have a DOS program program2.exe which reads a string from stdin and
  25. |return a exit code (used in batch file as errorlevel).
  26. |How do I pass mystring to the program2.exe and get a return code in C?
  27. |I can't sleep if this problem is not solved.  Please help !!!!
  28.  
  29. I ran into this problem several years ago when I was forced to use MSDOS.
  30. Sorry to disappoint you, but this brain dead OS-wannabe does not know 
  31. anything about such things as pipes. The `|`' symbol on the command line
  32. is processed by the shell (COMMAND.COM) and all it does is an freopen of
  33. the stdout for program1 into a temporary file. When program1 is finished,
  34. the second program is fired up with its stdin freopened using the temporary
  35. file. After program2 has finished, the file is removed. The shell simply
  36. fakes a pipe operation since MSDOS doesn't support this. 
  37.  
  38. So all you can do is: write your output to a file (maybe using freopen
  39. on stdout) and exec the second program after doing an freopen on stdin,
  40. using the same file. It's a kludge, I know ...
  41.  
  42. kind regards,
  43.  
  44. Jos aka jos@and.nl
  45.