🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #6440

Re: DOS CONSOLE OUTPUT

#6440
From: David Martin
Date: Sat, 12 Dec 1992 21:00
51 lines
2748 bytes
In article <1992Dec11.073326.10891@tc.cornell.edu> you write:
>    I am using fortran CALL FSYSTEM ('DOS COMMAND')
>to run various dos commands like MKDIR etc.  How do I get
>DOS to NOT write to the console during such operations, the
>console will be used for graphics application.  
> 
I started a thread 'Redirection to NUL from exec()' which you may have
seen, addressing the same problem from Turbo Pascal. I got lots of C
code and I was able to translate it quite easily into TP. I wish you
luck with Fortran, because I don't know a thing about it!

However, here is the pseudocode for the definitive solution:

1.  Open the device 'NUL' with whatever opens a file in Fortran.
2.  Get a copy of StdOut's filehandle with the dos service that does this,
    to a variable, eg. OrigStdOut. In C this is the dup() function. In TP
    I had to write my own. You can access it at the interrupt level by
    setting register AH to 45h, BX to the file handle you want a copy of
    (ie. 1=StdOut), and calling interrupt 21h. The copy of the (StdOut's)
    file handle is returned in AX.
3.  Call the dos service to duplicate a file handle, to equate NUL with
    StdOut, so the two move in unison. In C this is dup2(). In TP, again,
    I had to write my own... You set AH to 46h, BX and CX to the two
    handles of NUL and StdOut (1) respectively, and call 21h.
4.  Repeat 2 and 3 with StdErr (2) instead of StdOut.
5.  Close NUL.
6.  Do whatever, ie. CALL FSYSTEM ('DOS COMMAND')
7.  Execute step 3 again with BX = OrigStdOut and CX = StdOut then again
    with BX = OrigStdErr and CX = StdErr.
8.  Close OrigStdOut and OrigStdErr.

Reiterating, in a pseudo-language of my own invention:

1.  NulsHandle = open('nul')
2.  OrigStdOut = dup(1)
3.  dup2(NulsHandle,1)
4.  OrigStdErr = dup(2)
5.  dup2(NulsHandle,2)
6.  close(NulsHandle)
7.  call fsystem ('dos command')
8.  dup2(OrigStdOut,1)
9.  dup2(OrigStdErr,2)
10. close(OrigStdOut)
11. close(OrigStdErr)

I hope that that makes sense to you!

                  +--------------------------------------+
                  |          - David Martin -            |
                  |   InterNet : dwm@sound.demon.co.uk   |
                  +--------------------------------------+
Technical Details
Message-ID: <724219217snx@sound.demon.co.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!demon!sound.demon.co.uk!dwm

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
From: dwm@sound.demon.co.uk (David Martin)
Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!demon!sound.demon.co.uk!dwm
Subject: Re: DOS CONSOLE OUTPUT
Reply-To: dwm@sound.demon.co.uk
Cc: comp.os.msdos.programmer@sound.demon.co.uk
X-Mailer: cppnews $Revision: 1.20 $
Organization: Sound & Vision BBS (UK) 0932 252323
Lines: 51
Date: Sat, 12 Dec 1992 21:00:17 +0000
Message-ID: <724219217snx@sound.demon.co.uk>
Sender: usenet@demon.co.uk