I/O Redirection question

Jim Rogers jimr at hp-lsd.COS.HP.COM
Wed Apr 17 05:10:04 AEST 1991


David W. Smith writes:

I have a question regarding I/O redirection.  I have a program in which
writes to stdout and stderr.  I have redirected both of these to a file.

Now comes the problem.  I need to capture stdout in a file along with
stderr, but I also need stdout to go to the terminal for prompting of
input.  Is this possible?  If so, how does one do this?

Answers may be mailed to me directly or you may post responses.  A solution
in for the csh, sh, ksh are all acceptable.

Thank you,


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  David W. Smith
  NASA Ames Research Center			All comments are my own and
  (415) 604-6555				do not reflect NASA opinions
  Internet: dwsmith at ames.arc.nasa.gov		or policies.
  USPS: M/S 233-3
  Moffett Field, CA 94035-1000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----------

The following modest example should show you how to do it.
Note that both stderr and stdout are sent to a file and to the screen 
together.  This should make the program fully interactive.



#!/bin/ksh

a_process()
{
# select writes to stderr
	select action in "First Action" "Second Action" "Terminate Actions"
	do
		if [ -z "$action" ]
		then
# write error message to stderr
			print 2 "Unknown action\nPress return to continue"
		else
#write responses to stdout
		case ${REPLY} in
		1 | 2)	print "${action}";;
		3)	print "Bye...";exit;;
		esac
		fi
	done
}
a_process 2>&1 | tee /dev/tty >> foobar




Jim Rogers
Hewlett-Packard Company
Colorado Springs, Colorado



More information about the Comp.unix.shell mailing list