home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18629 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  1.0 KB

  1. Path: sparky!uunet!utcsri!relay.cs.toronto.edu!compuserve.com!76336.3114
  2. Newsgroups: comp.lang.c++
  3. From: 76336.3114@CompuServe.COM (Kevin Dean)
  4. Subject: Piping and return code
  5. Message-ID: <930101234017_76336.3114_EHJ42-3@CompuServe.COM>
  6. Date: 1 Jan 93 23:47:40 GMT
  7. Lines: 21
  8.  
  9. In an article dated Dec. 30, Binh Tong (tongb@woods.ulowell.edu) asks:
  10.  
  11. >Does any one know how to put redirect output and get return code in C ?
  12.  
  13. The ANSI-standard function freopen() followed by the appropriate spawn
  14. command can be used as follows:
  15.  
  16. FILE * newIn = freopen("LOGIN.IN", "r", stdin);    // Redirect input.
  17. int result = spawn...("LOGIN.EXE", ...);    // Run command.
  18. freopen("CON", "r", stdin);            // Restore input.
  19.  
  20. It's been a while since I did this so it may need some fiddling but I know
  21. for certain that freopen() will work.  Share and enjoy.
  22.  
  23. Kevin Dean
  24.  
  25. SNAG: acronym for Sensitive New-Age Goof, one who, without any relevant
  26. experience, is always willing to enlighten the ignorant masses on the
  27. social issue of the day.  Have you hit any SNAGs lately?
  28.  
  29.  
  30.