What "isatty"?

Joe Dellinger joe at hanauma
Sun May 21 17:47:27 AEST 1989


	I have a graphics driver program which has 2 basic behaviours.
If you do
	pspen < plot.data > file
it writes postscript code to "file". If you do
	pspen < plot.data
it spools the postscript for you.

	The way it tells whether the output is redirected or not is by
doing
	if ( isatty( fileno( stdout ) ) )
	{
	write into a temp file, then spool it
	}
	else
	{
	just write to stdout
	}

unfortunately, this doesn't work if the person runs the program in
background as part of a script, logs out, and nobody else happens
to be using the terminal when the program eventually runs. In this
case "isatty" answers "no" for either case.

Questions:
Where is stdout pointing in such a case? Where does stuff written to it go?

How can I tell whether stdout is redirected or not on the command line,
given that "isatty" turns out to not do the job?

We've had strange problems with the permissions on "/dev/tty" randomly
changing to "crw--w--w-", causing many strange errors. I think writing
to stdout and stderr when these are no longer attached to a terminal may
be causing this. Any similar experiences out there? The programs in question
are NOT running with any special privileges, so if they can somehow change
permissions on /dev/tty it is a bug in the OS.

If the answers to any of the above questions are obvious, please only
answer if you roll double sixes on a pair of dice on the first try!
\    /\    /\    /\/\/\/\/\/\/\.-.-.-.-.......___________
 \  /  \  /  \  /Dept of Geophysics, Stanford University \/\/\.-.-....___
  \/    \/    \/Joe Dellinger joe at hanauma.stanford.edu  apple!hanauma!joe\/\.-._



More information about the Comp.unix.wizards mailing list