Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!husc6!rice!uw-beaver!cornell!rochester!pt.cs.cmu.edu!MARCOZ.BOLTZ.CS.CMU.EDU!marcoz From: marcoz@MARCOZ.BOLTZ.CS.CMU.EDU (Marco Zagha) Newsgroups: comp.lang.c Subject: Re: getting users' tty # into a C program Summary: popen returns a FILE pointer not a descriptor Message-ID: <4418@pt.cs.cmu.edu> Date: 6 Mar 89 13:50:01 GMT References: <441@lakesys.UUCP> <9794@smoke.BRL.MIL> <52746@yale-celray.yale.UUCP> Organization: Carnegie-Mellon University, CS/RI Lines: 15 In article 52746@yale-celray.yale.UUCP> spolsky-joel@CS.YALE.EDU (Joel Spolsky) writes: > failing that try fd=popen("tty"); fscanf(fd,"%s",ttyname); close(fd) popen returns a FILE pointer. To close this file pointer use pclose(), not close(). I think this is what should be done (as you said, failing ttyname()): FILE *f; f=popen("/usr/bin/tty","r"); fscanf(f,"%s",ttyname); pclose(f) == Marco (marcoz@cs.cmu.edu) --