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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-01-2007, 03:00 PM
|
#1
|
Member
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76
Rep:
|
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!
|
|
|
10-01-2007, 06:56 PM
|
#2
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
|
|
|
10-01-2007, 10:16 PM
|
#3
|
Member
Registered: Sep 2007
Distribution: Fedora 7, Edubuntu
Posts: 35
Rep:
|
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
|
|
|
10-02-2007, 08:06 AM
|
#4
|
Member
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76
Original Poster
Rep:
|
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
|
|
|
10-02-2007, 12:44 PM
|
#5
|
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450
Rep:
|
Quote:
Originally Posted by WingnutOne
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.
|
|
|
All times are GMT -5. The time now is 11:36 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|