home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / msdos / programm / 11391 < prev    next >
Encoding:
Text File  |  1992-12-14  |  2.6 KB  |  65 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. From: dwm@sound.demon.co.uk (David Martin)
  3. Path: sparky!uunet!pipex!demon!sound.demon.co.uk!dwm
  4. Subject: Re: DOS CONSOLE OUTPUT
  5. Reply-To: dwm@sound.demon.co.uk
  6. Cc: comp.os.msdos.programmer@sound.demon.co.uk
  7. X-Mailer: cppnews $Revision: 1.20 $
  8. Organization: Sound & Vision BBS (UK) 0932 252323
  9. Lines: 51
  10. Date: Sat, 12 Dec 1992 21:00:17 +0000
  11. Message-ID: <724219217snx@sound.demon.co.uk>
  12. Sender: usenet@demon.co.uk
  13.  
  14. In article <1992Dec11.073326.10891@tc.cornell.edu> you write:
  15. >    I am using fortran CALL FSYSTEM ('DOS COMMAND')
  16. >to run various dos commands like MKDIR etc.  How do I get
  17. >DOS to NOT write to the console during such operations, the
  18. >console will be used for graphics application.  
  19. I started a thread 'Redirection to NUL from exec()' which you may have
  20. seen, addressing the same problem from Turbo Pascal. I got lots of C
  21. code and I was able to translate it quite easily into TP. I wish you
  22. luck with Fortran, because I don't know a thing about it!
  23.  
  24. However, here is the pseudocode for the definitive solution:
  25.  
  26. 1.  Open the device 'NUL' with whatever opens a file in Fortran.
  27. 2.  Get a copy of StdOut's filehandle with the dos service that does this,
  28.     to a variable, eg. OrigStdOut. In C this is the dup() function. In TP
  29.     I had to write my own. You can access it at the interrupt level by
  30.     setting register AH to 45h, BX to the file handle you want a copy of
  31.     (ie. 1=StdOut), and calling interrupt 21h. The copy of the (StdOut's)
  32.     file handle is returned in AX.
  33. 3.  Call the dos service to duplicate a file handle, to equate NUL with
  34.     StdOut, so the two move in unison. In C this is dup2(). In TP, again,
  35.     I had to write my own... You set AH to 46h, BX and CX to the two
  36.     handles of NUL and StdOut (1) respectively, and call 21h.
  37. 4.  Repeat 2 and 3 with StdErr (2) instead of StdOut.
  38. 5.  Close NUL.
  39. 6.  Do whatever, ie. CALL FSYSTEM ('DOS COMMAND')
  40. 7.  Execute step 3 again with BX = OrigStdOut and CX = StdOut then again
  41.     with BX = OrigStdErr and CX = StdErr.
  42. 8.  Close OrigStdOut and OrigStdErr.
  43.  
  44. Reiterating, in a pseudo-language of my own invention:
  45.  
  46. 1.  NulsHandle = open('nul')
  47. 2.  OrigStdOut = dup(1)
  48. 3.  dup2(NulsHandle,1)
  49. 4.  OrigStdErr = dup(2)
  50. 5.  dup2(NulsHandle,2)
  51. 6.  close(NulsHandle)
  52. 7.  call fsystem ('dos command')
  53. 8.  dup2(OrigStdOut,1)
  54. 9.  dup2(OrigStdErr,2)
  55. 10. close(OrigStdOut)
  56. 11. close(OrigStdErr)
  57.  
  58. I hope that that makes sense to you!
  59.  
  60.                   +--------------------------------------+
  61.                   |          - David Martin -            |
  62.                   |   InterNet : dwm@sound.demon.co.uk   |
  63.                   +--------------------------------------+
  64.