LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-01-2007, 03:00 PM   #1
WingnutOne
Member
 
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76

Rep: Reputation: 16
Question Pipe standard error?


Is there a way to redirect standard error to the input of another command (BASH / RHE4)?
I can send it to a file, grep the file for what I need, then delete the file, but this method seems a bit sloppy.

Is there a more efficient way to do it?
(I tried redirecting stderr to stdout, then greping for what I need, but stdout occasionally includes text that fowls up my grep sequence.)

Thanks!
 
Old 10-01-2007, 06:56 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
You should be able to just swap the file descriptors for stdout
and stderr if stderr is all you need to post-process...

Code:
(cmd1 | cmd2) 3>&1 1>&2 2>&3

Cheers,
Tink
 
Old 10-01-2007, 10:16 PM   #3
I_like_TUX
Member
 
Registered: Sep 2007
Distribution: Fedora 7, Edubuntu
Posts: 35

Rep: Reputation: 15
Tinkster taught me a way to put everything in one line because I used to do : exec 3>&1 ... cmd1 | cmd2

Actually, it is an interesting question and also a good practice. I explored a little bit and found that if you want stdout of cmd1 to disappear and only stderr of cmd1 piped into cmd2 without being displayed, you can do the following:

I wrote a sample script for testing:
#!/bin/bash
echo "output for stdout" >&1
echo "output for stderr" >&2
exit 0

$ (./a_cmd.sh | wc -l) 3>&1 1>&2 2>&3
output for stderr
1

$ (./a_cmd.sh | wc -l) 3>&1 1>/dev/null 2>&1 1>&3
1

Tinkster, the above works but I don't know how it works. Can you explain? Thanks.

Last edited by I_like_TUX; 10-02-2007 at 01:25 AM. Reason: remove un-needed stuffs
 
Old 10-02-2007, 08:06 AM   #4
WingnutOne
Member
 
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76

Original Poster
Rep: Reputation: 16
Maybe I'm more of a no0b than you realize: I know "1" is stdout and "2" is stderr, but what's the "3" mean? Stdout and stderr combined?

Like IlTux above, I can plug different commands into the formula and get different results, but I don't know what's really happening to generate the differences.

Last edited by WingnutOne; 10-02-2007 at 08:44 AM. Reason: remove pun, add content
 
Old 10-02-2007, 12:44 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 79
Quote:
Originally Posted by WingnutOne View Post
Maybe I'm more of a no0b than you realize: I know "1" is stdout and "2" is stderr, but what's the "3" mean? Stdout and stderr combined?
It’s just a placeholder file descriptor. See man exec.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what does "standard error was duplicated as standard output" mean? nickleus Linux - General 4 09-15-2006 06:14 AM
ftp -n pipe for error camilian Linux - Newbie 1 08-23-2006 12:35 PM
PWC - Broken pipe error taladan Linux - Software 5 06-05-2006 03:00 PM
Broken Pipe error with rpmbuild in rh9 tuxfood Red Hat 1 05-21-2005 04:30 PM
Broken Pipe Error ken734 Linux - Newbie 6 09-04-2003 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:36 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration