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