Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 29 Jul 2014, 19:36
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
How to capture (command line) screen output in a file
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [2 Posts]  
Author Message
kethd

Joined: 20 Oct 2005
Posts: 451
Location: Boston MA USA

PostPosted: Thu 22 Dec 2005, 12:31    Post subject:  How to capture (command line) screen output in a file  

How to capture command line screen text output in a logfile and still have it show on the screen

This sample code can be included in an ash/bash shell script:
Code:
rm PIPE1
mkfifo PIPE1
#cat >logfile1 <PIPE1 &
cat <PIPE1 &

rm PIPE2
mkfifo PIPE2
cat >logfile2 <PIPE2 &
#cat <PIPE2 &

rm PIPE0
mkfifo PIPE0
tee PIPE1 >PIPE2 <PIPE0 &

exec 1>PIPE0 2>&1

# now all STDOUT and STDERR is copied to logfile2 and is also still sent to the screen

echo starting
lsof -R | grep PI #sample output
echo bye

This is a great way to really get to know mkfifo and tee. After you make a named pipe with mkfifo, you must connect the pipe to an output before you can connect it to an input. The & at the end of the line makes the script keep going while the spawned subtask is running.

Note:
This is the hard way to do this. There is a program called script that is supposed to be able to capture all input and output in a spawned sub-shell. And it is easy to run a script and capture the output:
# sh script.sh 2>&1 | tee logfile
The above example is for situations where you want to be able to do these kinds of dynamic plumping redirections from within a script, operating at the current shell level.
Back to top
View user's profile Send private message 
thoughtjourney

Joined: 04 May 2005
Posts: 61
Location: Sutton, NSW

PostPosted: Tue 27 Dec 2005, 17:49    Post subject:  

Thanks, kethd. Good to know.
_________________
in the beginning was the Logos

http://thoughtjourney.aus.cc
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [2 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0476s ][ Queries: 12 (0.0081s) ][ GZIP on ]