🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #8442

i/o redirection in msdos

#8442
From: Fred Smith
Date: Mon, 11 Dec 1989 18:21
42 lines
1830 bytes

I have recently run into an issue where I need to DISABLE temporarily any
i/O redirection that may be in effect.

I have a program that allows the user to escape to a subhsell. If there is
currently any i/o redirection it is, of course, inherited by the child
shell. In this case, the only redirection that exists is that stdin may be
redirected to a file.

I have tried the following:

int old;
FILE * new;

...

old = dup(fileno(stdin));
new = freopen ("CON", "r", stdin);
/* stuff here to do the subhell */
stream = fdopen (old, "r");

At first sight, this all seems to work ok. I can go to a subshell and
all seems fine there, and I can return to my main program and all
still seems fine. However the SECOND time I try to do this to go
back to another subshell, the redirection is not un-done correctly,
in some way I have not been able to diagnose--the keyboard is
non-functional and I find I have to hit the hardware reset
button to get out of it.  After the first time this is done the
fdopen() call returns the same value that stdin had before doing
any of this stuff, which seems to make sense.

Obviously, I am doing something wrong here, but I don't see what it
is. Can any of the wizards out there shed some light on this ?? This
is on PC-DOS 3.3 and MSC 5.1. I would like a method which is not
dependent on any features which were unavailable before 3.0, i.e.,
one which will also work on DOS >= 2.0.

Thanks!

Fred Smith
uunet!samsung!cg-atla!fredex
Technical Details
Message-ID: <8157@cg-atla.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!samsung!cg-atla!fredex

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!samsung!cg-atla!fredex
From: fredex@cg-atla.UUCP (Fred Smith)
Newsgroups: comp.sys.ibm.pc
Subject: i/o redirection in msdos
Message-ID: <8157@cg-atla.UUCP>
Date: 11 Dec 89 18:21:05 GMT
Reply-To: fredex@cg-atla.UUCP (Fred Smith)
Organization: Agfa Compugraphic Division
Lines: 42