Odd vi behaviour inside a shell script.

Dan Mercer mercer at ncrstp.StPaul.NCR.COM
Tue May 8 02:40:56 AEST 1990


In article <1284 at telsys.aut.UUCP> jsmithso at aut.UUCP (Jim Smithson) writes:
:
:Here's a small problem I can't really explain.
:I am running /bin/sh on my NCR Tower 32/650 under Sys V rel 2.01.
:
:Consider a shell script called foo.sh which contains the following two lines:
:
:vi foofile
:not_a_command 	# here to give some error output
:
:I want to run this shell script and capture the output (stdout and stderr)
:to a logfile, I also want to see the output as it happens.
:
:So I enter the command:		foo.sh 2>&1 |tee foo.log
:But this totally hoses up `vi`. `vi` runs fine if I enter: foo.sh |tee foo.log
:But stderr is not written to the logfile. Same with: foo.sh | tee foo.log 2>&1
:`vi` also runs fine if I enter: foo.sh 2>&1
:
:Can anybody explain what the problem is?
:Can anybody suggest something that will work?
:
:Thanks in advance!
:-- 
:James R. Smithson	Ascom Autelca AG      CH-3073 Guemligen/Switzerland
:E-mail: jsmithso at aut.UUCP   FAX: +41 31 527 745   Voice : +41 31 529 214
:UUCP: ...!uunet!mcsun!chx400!hslrswi!aut!jsmithso


Vi uses stderr on the ioctl call that sets it up for raw data
handling.  If stderr is redirected,  the terminal will not be in the 
correct state,  and all the full screen algorithms will be off.  I
know of no way around this.

However,  ex works quite well with stdout and stderr redirected,
since it does not use raw mode (you exit insert mode by typing
a standalone period and an enter).  When I wanted capture my
macro mappings for a seminar I was giving on vi,  that's what I
did.
-- 

Dan Mercer
Reply-To: mercer at ncrstp.StPaul.NCR.COM (Dan Mercer)



More information about the Comp.unix.questions mailing list