home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19295 < prev    next >
Encoding:
Text File  |  1993-01-06  |  2.0 KB  |  64 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!Germany.EU.net!news.Hamburg.Germany.EU.net!jwminhh!wieck
  3. From: wieck@jwminhh.hanse.de (Jan Wieck)
  4. Subject: Re: Piping and return code again! Please help !!!
  5. Message-ID: <1993Jan7.001626.2172@jwminhh.hanse.de>
  6. Organization: Private Site under Mach386
  7. X-Newsreader: Tin 1.1 PL4
  8. References: <1993Jan4.212844.1@woods.ulowell.edu>
  9. Date: Thu, 7 Jan 1993 00:16:26 GMT
  10. Lines: 52
  11.  
  12. tongb@woods.ulowell.edu writes:
  13. :
  14. : Please help!!!!!
  15. :
  16. : How do we make piping works in C for a DOS system?
  17. :
  18. : Dos offers:
  19. :
  20. : c:> program1 | program2
  21. :
  22. : to pass the output of the program1 as the input of the program2.  Now if we
  23. : have a C var declared as
  24. :
  25. : char mystring[] = "this is a string";
  26. :
  27. : and we have a DOS program program2.exe which reads a string from stdin and
  28. : return a exit code (used in batch file as errorlevel).
  29. :
  30. : How do I pass mystring to the program2.exe and get a return code in C?
  31. :
  32. : I can't sleep if this problem is not solved.  Please help !!!!
  33.  
  34.  
  35.         Poor boy, you got the wrong job! But don't worry, be hap-
  36.         py - here's the solution.
  37.  
  38.         Just use something like this (I know, it's a hack):
  39.  
  40.             ...
  41.             int retval;
  42.             char cmd[128];      /* DOS-commandline cannot exceed 127
  43.                                  * char's as a heir of CP/M - so it's
  44.                                  * O.K. to be hardcoded until 2038 :-)
  45.                                  */
  46.             ...
  47.             sprintf(cmd, "echo \"%s\" | program2", mystring);
  48.             retval = system(cmd);
  49.             ...
  50.  
  51.         Remember, that this isn't portable.  The  syntax  of  the
  52.         commandline  may  be  wrong for the OS or no echo-command
  53.         may exist. Also possible is, that system(3)  doesn't  re-
  54.         turn any exit-status of the executed command.
  55.  
  56.  
  57. Until later, Jan
  58.  
  59. -- 
  60. # Any language keeps its own misunderstandings; #
  61. # why shouldn't programming languages do?       #
  62. #                                               #
  63. #            wieck@jwminhh.hanse.de (Jan Wieck) #
  64.