Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!sunybcs!ugkamins From: ugkamins@sunybcs.uucp (John Kaminski) Newsgroups: comp.unix.wizards Subject: Re: unix question about stdin Message-ID: <5414@cs.Buffalo.EDU> Date: 22 Apr 89 05:19:13 GMT References: <3398@udccvax1.acs.udel.EDU> Sender: nobody@cs.Buffalo.EDU Reply-To: ugkamins@sunybcs.UUCP (John Kaminski) Organization: SUNY/Buffalo Computer Science Lines: 21 The original post wanted to know how to reconnect the stdin to the terminal after it had been attached to a file, assumedly through redirection. What I just tried on a BSD system, and works: fclose(stdin); *stdin = *fopen("/dev/tty", "r"); The "*" before stdin is necessary because of the way stdin is defined in . Another method that SHOULD work is akin to the way I've seen some shell code do it: close(0); dup2(0, open("/dev/tty", O_RDONLY, 0x700)); Of course, this doesn't check for a failed open() call. Also, I guess: close(0); dup(open("/dev/tty", O_RDONLY, 0x700)); SHOULD work. Note that any of read, write, or read/write should be OK, as well as many different file modes (last arg to open()).