Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!mcnc!decvax!mandrill!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon Allbery) Newsgroups: comp.unix.wizards Subject: Re: Redirect Output in the Middle of a Program?? Message-ID: <7699@ncoast.UUCP> Date: 4 May 88 19:44:36 GMT References: <13085@brl-adm.ARPA> <3571@gryphon.CTS.COM> <2841@cvl.umd.edu> Reply-To: allbery@ncoast.UUCP (Brandon Allbery) Followup-To: comp.unix.wizards Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 79 As quoted from <2841@cvl.umd.edu> by liuqing@cvl.umd.edu (Larry Liuqing Huang): +--------------- | Now more people are dialing into a system via telephone lines. It is | not unusual that the connection died out in the middle of a big C | program which you hate to start running from the beginning again. | Is it possible for the C program or Shell to detect the line problem? +--------------- From the time the program starts, the shell has no control over the program's I/O. You would have to patch stdio to detect SIGHUP on an fd attached to the controlling terminal. (Ecch!) I use the following scripts instead. (4.xBSDers will, of course, want to change the names....) ----------------------------------- cut here ----------------------------------- : bg - run program in the background (essentially nohup) case $# in 0) echo "Usage: bg command [args]" >&2 exit 1 esac > ./do.out { [ "$TERM" = vt100 ] && echo '\033[1q\c' trap '' 3 2 1 { eval nice -20 "$@" } > ./do.out 2>&1 [ "$TERM" = vt100 ] && echo '\033[q\c' if [ $? -ne 0 ]; then echo '\007\c' [ "$TERM" = vt100 ] && echo '\033[4q\c' sleep 1 fi echo '\007\c' sleep 1 echo '\007\c' } & ----------------------------------- cut here ----------------------------------- ----------------------------------- cut here ----------------------------------- : fg - run command in background, catching output which is displayed case "$#" in 0) echo "usage: fg command [args]" >&2 exit 1 ;; esac > ./do.out { SHELL=/bin/sh export SHELL case "$TERM" in vt1??) echo '\033[q\033[1q\c' ;; esac trap '' 3 2 1 eval nice -20 "sh -c '$@' > ./do.out 2>&1 < /dev/null" rc=$? case "$TERM" in vt1??) echo '\033[q\c' ;; esac case $rc in 0) ;; *) echo '\007\c' case "$TERM" in vt100) echo '\033[4q\c' ;; vt1??) echo '\033[2q\c' ;; esac # sleep 1 esac echo '\007\c' sleep 1 echo '\007\c' kill -2 $$ 2> /dev/null } & exec tail -f ./do.out ----------------------------------- cut here ----------------------------------- -- Brandon S. Allbery, moderator of comp.sources.misc {well!hoptoad,uunet!marque,cbosgd,sun!mandrill}!ncoast!allbery Delphi: ALLBERY MCI Mail: BALLBERY