LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 12-26-2009, 02:11 PM   #1
solo9300
LQ Newbie
 
Registered: Sep 2009
Posts: 13

Rep: Reputation: 0
Shell script stdout, stderr and stdin


Hello all,
what i am try to do is control stdout, stderr and stdin.

For example:

Shell Script File:
Code:
     wget http://ufpr.dl.sourceforge.net/sourceforge/pyxml/PyXML-0.8.4.tar.gz >> MyLogFile
     tar xvfz PyXML-0.8.4.tar.gz >> MyLogFile
     cd PyXML-0.8.4 >> MyLogFile
     python setup.py install >> MyLogFile
when run the script i want to
print stdin
print stderr like this "Error: stderr"
don't print stdout

and save all stdout, stderr and stdin to MyLogFile

Any help would be much appreciated.
 
Old 12-27-2009, 12:17 AM   #2
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Rep: Reputation: 15
Code:
./script &> log
will output the stdrr and stdout but for the stdin?
 
Old 12-28-2009, 12:54 AM   #3
solo9300
LQ Newbie
 
Registered: Sep 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by deepinlife View Post
Code:
./script &> log
will output the stdrr and stdout but for the stdin?
and if i want to print the error between [PrintTheError]
 
Old 12-28-2009, 01:51 AM   #4
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Rep: Reputation: 15
Quote:
Originally Posted by solo9300 View Post
and if i want to print the error between [PrintTheError]
i can't understand what do u mean ?
all error logged to stdrr will be redirected to file log
 
Old 12-28-2009, 02:39 PM   #5
solo9300
LQ Newbie
 
Registered: Sep 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by deepinlife View Post
i can't understand what do u mean ?
all error logged to stdrr will be redirected to file log
what i mean is to write to a log file yes, pluss print a msg to the terminal saying there was an error + the error

echo "there is an Error $stderr"

Last edited by solo9300; 12-28-2009 at 02:41 PM.
 
Old 12-28-2009, 11:06 PM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,242
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
try this one
Code:
#!/bin/bash

exec 2>&-
exec 2> >(while read LINE; do echo "Error: $LINE"; done)

<commands here>

exec 2>&-
exec 2>/dev/stderr || exec 2>/dev/fd/2    # optional
you'll need bash >=2.05 to run the script

---- edit ----

another variation:

Code:
{
    <commands here>
} 2> >(while read LINE; do echo "Error: $LINE"; done)

Last edited by konsolebox; 12-28-2009 at 11:09 PM.
 
Old 12-29-2009, 12:33 AM   #7
solo9300
LQ Newbie
 
Registered: Sep 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by konsolebox View Post
try this one
Code:
{
    <commands here>
} 2> >(while read LINE; do echo "Error: $LINE"; done)
work grate thax
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to change stdin, stdout & stderr in u-boot to ethernet from serial jynthms Linux - Newbie 1 04-01-2009 09:34 AM
redirecting BASH script stdout/stderr from the script itself Hewson Linux - General 4 04-18-2008 03:32 PM
shell script: how to send stdout one place & stderr another? BrianK Programming 8 09-21-2007 06:57 AM
Shell script - stdout & stderr to terminal and file jantman Linux - Software 1 12-07-2006 04:34 PM
shell short question(stdout, stderr) blackzone Programming 4 11-11-2004 09:01 AM


All times are GMT -5. The time now is 11:31 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration