home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcsun!Germany.EU.net!news.Hamburg.Germany.EU.net!jwminhh!wieck
- From: wieck@jwminhh.hanse.de (Jan Wieck)
- Subject: Re: Piping and return code again! Please help !!!
- Message-ID: <1993Jan7.001626.2172@jwminhh.hanse.de>
- Organization: Private Site under Mach386
- X-Newsreader: Tin 1.1 PL4
- References: <1993Jan4.212844.1@woods.ulowell.edu>
- Date: Thu, 7 Jan 1993 00:16:26 GMT
- Lines: 52
-
- 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 !!!!
-
-
- Poor boy, you got the wrong job! But don't worry, be hap-
- py - here's the solution.
-
- Just use something like this (I know, it's a hack):
-
- ...
- int retval;
- char cmd[128]; /* DOS-commandline cannot exceed 127
- * char's as a heir of CP/M - so it's
- * O.K. to be hardcoded until 2038 :-)
- */
- ...
- sprintf(cmd, "echo \"%s\" | program2", mystring);
- retval = system(cmd);
- ...
-
- Remember, that this isn't portable. The syntax of the
- commandline may be wrong for the OS or no echo-command
- may exist. Also possible is, that system(3) doesn't re-
- turn any exit-status of the executed command.
-
-
- Until later, Jan
-
- --
- # Any language keeps its own misunderstandings; #
- # why shouldn't programming languages do? #
- # #
- # wieck@jwminhh.hanse.de (Jan Wieck) #
-