david@wubios.wustl.edu (David J. Camp) (02/21/89)
I am trying to use this invokation: if (isatty (stdin)) to detect whether a C program has been called interactively or with redirection. It does not work. Can anyone suggest a better way, or explain why it does not work? I am using a Sun 3/260 running SunOS 4.0.1. -David- -- Bitnet: david@wubios.wustl ^ Mr. David J. Camp Internet: david%wubios@wucs1.wustl.edu < * > Box 8067, Biostatistics uucp: uunet!wucs1!wubios!david v 660 South Euclid Washington University Medical School Saint Louis, MO 63110
david@wubios.wustl.edu (David J. Camp) (02/21/89)
I forgot to mention in my previous note the symptoms of isatty(stdin) when it fails. It always returns 0. I also tried using ttyname(stdin), but it always returns NULL. -David- -- Bitnet: david@wubios.wustl ^ Mr. David J. Camp Internet: david%wubios@wucs1.wustl.edu < * > Box 8067, Biostatistics uucp: uunet!wucs1!wubios!david v 660 South Euclid Washington University Medical School Saint Louis, MO 63110
rodolfom@hplsla.HP.COM (Rodolfo Mancisidor) (02/23/89)
>I am trying to use this invokation: > > if (isatty (stdin)) isatty() expects a file descriptor (an integer) you are passing a file pointer (FILE *) try: if (isatty(0)) ___ ___ _________ /_ /| /_ /| /_______ /| |##| | |##| | |########| | |##| |_|##| | |##| L|##| | |##|/__|##| | |##|/_|##| | Rodolfo Mancisidor Lake |#########| | |########|/ [ [ 1[206] ] 335 ] 2912 Stevens |##| | |##| | |##| | 8600 Soper Hill Road Instruments |##| | |##| | |##| | Everett, WA 98205-1298 Division |##|/ |##|/ |##|/ rodolfom%hplsla@hplabs.hp.com (LSID)
maart@cs.vu.nl (Maarten Litmaath) (02/23/89)
david@wubios.wustl.edu (David J. Camp) writes:
\ if (isatty (stdin))
isatty(fileno(stdin))
^^^^^^
RTFM.
--
"Those who do not understand Henry |Maarten Litmaath @ VU Amsterdam:
Spencer are condemned to reinvent DOS." |maart@cs.vu.nl, mcvax!botter!maart
gwyn@smoke.BRL.MIL (Doug Gwyn ) (02/23/89)
In article <314@wubios.wustl.edu> david@wubios.wustl.edu (David J. Camp) writes: > if (isatty (stdin)) >explain why it does not work? Because you didn't RTFM. Try if ( isatty( fileno( stdin ) ) )
mue@ugun21.UUCP (02/23/89)
Both functions (isatty, ttyname) need a file descriptor as a parameter, not a file pointer. So you have to specify if (isatty(0 /*stdin */) ... rsp. if (ttyname(0) != NULL) ... ...mcvax!unido!hmueller.pad