1830042 Members
2272 Online
109998 Solutions
New Discussion

Redirect stderr

 
Starrynight
Advisor

Redirect stderr

Hi all

I have a problem with disks and when I enter vgdisplay an error is displayed. I would like to capture that error so I make:
[comand] > /tmp/outputfile 2>&1
...but I get nothing in /tmp/outputfile. I continue to see the error message only in display...can't capture it....
Am I doing something wrong?

Thanks in advance
SN
System administrator
9 REPLIES 9
Shaikh Imran
Honored Contributor

Re: Redirect stderr

Hi,
What is the type of shell you are working in ?
Simply try this
command > /tmp/outputfile.
OR
command >> /tmp/outputfile.
this should work.

Regs
I'll sleep when i am dead.
Jean-Luc Oudart
Honored Contributor

Re: Redirect stderr

2>&1

no space if you have any !

Regards,
Jean-Luc
fiat lux
Karthik S S
Honored Contributor

Re: Redirect stderr

Try,

command >> command.out 2>&1

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Nicolas Dumeige
Esteemed Contributor

Re: Redirect stderr

Maybe the command doesn't differenciate stdout and stderr (For instance sqlplus doesn't).

If all redirection fail, I've seen that, use exec to redirect you stty to a file, don't forget to retsore it after.
All different, all Unix
Sanjay Kumar Suri
Honored Contributor

Re: Redirect stderr

If you are using rsh (restricted) shell redirection will not work.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Naveej.K.A
Honored Contributor

Re: Redirect stderr

Hi,

You should do it in the following way

command 2>&1 /tmp/outputfile

This will work for you

With best wishes
Naveej
practice makes a man perfect!!!
Mark Grant
Honored Contributor

Re: Redirect stderr

Some commands write directly to the terminal (which they shouldn't). However, "vgdisplay" does not seem to be one of them.

I just did "vgdisplay > output" on our cluster which produces errors to the screen and normal output to the file "output" as you would expect. Then "vgdisplay > output 2>&1" sent all output, including the errors to file "output", again as expected.

Is your [command] vgdisplay or is it something else?

Never preceed any demonstration with anything more predictive than "watch this"
SureshKumar_2
Valued Contributor

Re: Redirect stderr

Hi SN

Try this it is working.....

[command] 2>&1 /tmp/outputfile
---

vgdisplay 2>&1 /tmp/outputfile
"vgdisplay 2>&1 /tmp/outputfile"

If u want error on different file, u can also do like this. This will put output into /tmp/outputfile and error in to /tmp/errorfile.

vgdisplay > /tmp/outputfile 2> /tmp/errorfile

Things are very easy, when u know about it...
Starrynight
Advisor

Re: Redirect stderr

Hi again

So...stupid me was making a big mistake...making a grep before redirecting stderr. Sorry, after all it works as it should ([comand] > /tmp/outputfile 2>&1).
Thanks for the answers nevertheless.

Regards
SN
System administrator