📄 ch42_08.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 42] 42.8 Errors Erased Too Soon? Try These Workarounds </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:52:38Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch42_01.htm"TITLE="42. Problems with Terminals"><LINKREL="prev"HREF="ch42_07.htm"TITLE="42.7 termtest: Send Repeated Characters to Terminal "><LINKREL="next"HREF="ch43_01.htm"TITLE="43. Printing"></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch42_07.htm"TITLE="42.7 termtest: Send Repeated Characters to Terminal "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 42.7 termtest: Send Repeated Characters to Terminal "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 42<BR>Problems with Terminals</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="CHAPTER"HREF="ch43_01.htm"TITLE="43. Printing"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43. Printing"BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-7899">42.8 Errors Erased Too Soon? Try These Workarounds </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-47269"></A>I just made a change to my<SPANCLASS="link"><EMCLASS="emphasis">.exrc</EM> file (<ACLASS="linkend"HREF="ch04_09.htm"TITLE="Setting Up vi with the .exrc File ">4.9</A>)</SPAN>.Then I started <EMCLASS="emphasis">vi</EM> and noticed a message in reverse video before thescreen cleared and my file was displayed.It was probably an error message.But <EMCLASS="emphasis">vi</EM>, like some other programs, shows errors and thenclears (erases) the screen before you can read them.Great design, eh?</P><PCLASS="para">Here are some workarounds:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para">When my terminal used to run at a slow data rate (1200 baud or less),I could usually read an error message before the screen cleared.In these days of 28,800 bps and above, you can still fake that.Log out.Then set your terminal or communicationspackage to a slow data rate and log in again.Now look fast.</P></LI><LICLASS="listitem"><PCLASS="para">Way back, when<SPANCLASS="link">ttys were real teletypes (<ACLASS="linkend"HREF="ch41_02.htm"TITLE="stty and All That Stuff ">41.2</A>)</SPAN>,finding errors was easy: there was no screen to clear; the error wasright there on the paper.</P><PCLASS="para">So, if your terminal has a printer, turn it on.(On DOS, try doing <KBDCLASS="keycap">[CTRL]</KBD>+<KBDCLASS="keycap">[PrtSC]</KBD>.)Re-run your program and read the error on the paper.</P></LI><LICLASS="listitem"><PCLASS="para">If your window or communications program has a "capture to file" function,turn it on.Make the error happen.Turn off the capture function (important!).Then read the file - you'll probably need to use a program like<SPANCLASS="link"><EMCLASS="emphasis">cat -v</EM> (<ACLASS="linkend"HREF="ch25_07.htm"TITLE="Show Non-Printing Characters with cat -v or od -c ">25.7</A>)</SPAN>or<SPANCLASS="link"><EMCLASS="emphasis">vmore</EM> (<ACLASS="linkend"HREF="ch25_05.htm"TITLE="Page Through Compressed, RCS, Unprintable Files ">25.5</A>)</SPAN>to keep the screen-clearing characters stored in the file from erasingyour screen as you read the file!</P></LI><LICLASS="listitem"><PCLASS="para">If you don't have a screen-capture function, but you do have the<SPANCLASS="link"><EMCLASS="emphasis">script</EM> (<ACLASS="linkend"HREF="ch51_05.htm"TITLE="Copy What You Do with script ">51.5</A>)</SPAN>program,use it with the technique in the step above.</P></LI><LICLASS="listitem"><PCLASS="para">If your window has a scroll bar or a "page up" command, try it.Some screen-clear commands won't clear the scrolling memory.</P></LI><LICLASS="listitem"><PCLASS="para">Use<SPANCLASS="link"><EMCLASS="emphasis">tee</EM> (<ACLASS="linkend"HREF="ch13_09.htm"TITLE="Send Output Two or More Places with tee ">13.9</A>)</SPAN>to grab the standard output and standard error to a filewhile you're viewing:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch13_05.htm"TITLE="13.5 Redirection in C Shell: Capture Errors, Too? ">|&</A> <ACLASS="co"HREF="ch08_13.htm"TITLE='8.13 Is It "2>&1 file" or "> file 2>&1"? Why?'>2>&1</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>vi foo |& tee saved_stuff</B></CODE> <ICLASS="lineannotation">...csh</I>$ <CODECLASS="userinput"><B>vi foo 2>&1 | tee saved_stuff</B></CODE> <ICLASS="lineannotation">...sh</I></PRE></TD></TR></TABLE></P><PCLASS="para">Then look at the saved file with a pager program, possibly filteringit through <SPANCLASS="link"><EMCLASS="emphasis">cat -v</EM> (<ACLASS="linkend"HREF="ch25_07.htm"TITLE="Show Non-Printing Characters with cat -v or od -c ">25.7</A>)</SPAN>and/or <SPANCLASS="link"><EMCLASS="emphasis">fold</EM> (<ACLASS="linkend"HREF="ch43_08.htm"TITLE="Fixing Margins with pr and fold ">43.8</A>)</SPAN>first. (The <SPANCLASS="link"><EMCLASS="emphasis">vmore</EM> script (<ACLASS="linkend"HREF="ch25_05.htm"TITLE="Page Through Compressed, RCS, Unprintable Files ">25.5</A>)</SPAN>was made for just this kind of job.)</P></LI><LICLASS="listitem"><PCLASS="para">Restart the program and get to the point just before the error will happen.Try to hitCTRL-s orHOLD SCREENbetween the time the error is output and the screen clears.That can be tough to doover a networkor on a high-speed connection, though, because of the delay between thetime you press the key and the time when all the output finally stopscoming.</P></LI><LICLASS="listitem"><PCLASS="para"><SPANCLASS="link">Temporarily switch (<ACLASS="linkend"HREF="ch06_10.htm"TITLE="Running a Command with a Temporarily Different Environment ">6.10</A>)</SPAN>to a <EMCLASS="emphasis">termcap/terminfo</EM> definition that doesn'thave a clear-screen capability.Two good settings for TERM are <EMCLASS="emphasis">dumb</EM> and <EMCLASS="emphasis">unknown</EM>.</P></LI><LICLASS="listitem"><PCLASS="para">That previous trick will leave your program almost useless, if it runs at all.If you do a lot of troubleshooting of full-screen programs like <EMCLASS="emphasis">vi</EM>or writing startup files such as <EMCLASS="emphasis">.exrc</EM>,it's worth your time to find a <EMCLASS="emphasis">termcap</EM> or <EMCLASS="emphasis">terminfo</EM> definitionthat has all the capabilities of the usual definition - except that itwon't clear the screen.(You'll probably want to check the termcap capabilities <EMCLASS="emphasis">cl=</EM>,<EMCLASS="emphasis">is=</EM>, <EMCLASS="emphasis">if=</EM>, <EMCLASS="emphasis">rs=</EM>, <EMCLASS="emphasis">rf=</EM>, <EMCLASS="emphasis">r2=</EM>, and maybe <EMCLASS="emphasis">ti=</EM>.Or, for <EMCLASS="emphasis">terminfo</EM>, look at <EMCLASS="emphasis">clear=</EM>, <EMCLASS="emphasis">iprog=</EM>, <EMCLASS="emphasis">is2=</EM>,<EMCLASS="emphasis">if=</EM>, <EMCLASS="emphasis">rs2=</EM>, <EMCLASS="emphasis">rf=</EM>, and maybe <EMCLASS="emphasis">smcup=</EM>.)If you don't know how, read O'Reilly & Associates' <EMCLASS="emphasis">termcap & terminfo</EM>-orlure a UNIX guru from down the hall somewhere.[1]</P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[1] Hint: all computer gurus like pizza.</P></BLOCKQUOTE></LI></UL><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch42_07.htm"TITLE="42.7 termtest: Send Repeated Characters to Terminal "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 42.7 termtest: Send Repeated Characters to Terminal "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="CHAPTER"HREF="ch43_01.htm"TITLE="43. Printing"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43. Printing"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">42.7 termtest: Send Repeated Characters to Terminal </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">43. Printing</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -