Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 29th, 2010, 10:19 PM
RAJ_55555's Avatar
RAJ_55555 RAJ_55555 is offline
Hats off to Mr. Joseph donahue
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2009
Posts: 749 RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 50 m 39 sec
Reputation Power: 1105
Doesn't get redirected to std error

I am not really a Linux or unix user, so apologies if the question seems too easy to be asked on the forum, but I tried using the search engines and failed.
Code:
cat < foo 2> bar

why doesn't this get redirected to stderror on error conditions?

Reply With Quote
  #2  
Old November 29th, 2010, 11:08 PM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,701 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 5 h 23 m 54 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
What shell are you using? bash? sh?

Reply With Quote
  #3  
Old November 30th, 2010, 08:44 AM
RAJ_55555's Avatar
RAJ_55555 RAJ_55555 is offline
Hats off to Mr. Joseph donahue
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2009
Posts: 749 RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 50 m 39 sec
Reputation Power: 1105
oh! Sorry.
Using Ubuntu 9, bash shell.

Reply With Quote
  #4  
Old November 30th, 2010, 11:22 AM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,701 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 5 h 23 m 54 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
By "redirected to stderror" (it's called just stderr, by the way) are you thinking that everything cat outputs will go there if there's a problem? Because that's not how it works: cat can choose whether to output to stdout or stderr and, as per general Unix convention, it'll output normal stuff to stdout and warning messages to stderr.

1. Does foo exist? Is it a file, directory, or something else?
2. What output do you get? What's in bar?
3. What output do you expect? What do you expect to see in bar?

Reply With Quote
  #5  
Old November 30th, 2010, 10:30 PM
RAJ_55555's Avatar
RAJ_55555 RAJ_55555 is offline
Hats off to Mr. Joseph donahue
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2009
Posts: 749 RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 50 m 39 sec
Reputation Power: 1105
Quote:
Originally Posted by requinix
are you thinking that everything cat outputs will go there if there's a problem?

Yes. Isn't it right?
Quote:
Originally Posted by requinix
it'll output normal stuff to stdout and warning messages to stderr.

you are also saying the same thing, or may be I didn't understand. please clarify.

Quote:
Originally Posted by requinix
Does foo exist? Is it a file, directory, or something else?

No. If foo exists, then as expected it prints the contents of the file. But if it doesn't the error message is also printed on the terminal. I expect it to be redirected to the file 'bar', which also doesn't exist, but I think it is created automatically.
I tried a couple of things, and it behaves as I expected it to by using this:
Code:
(cat < foo) 2> bar

Reply With Quote
  #6  
Old December 1st, 2010, 06:45 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 41 m
Reputation Power: 1485
You don't really need to redirect stdin into cat ...

Code:
cat foo 2> bar


is a 'cleaner' way of doing it.
Comments on this post
ishnid agrees: Yes, this is the way to do it.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #7  
Old December 1st, 2010, 07:50 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 36 m 34 sec
Reputation Power: 3885
Quote:
Originally Posted by RAJ_55555
No. If foo exists, then as expected it prints the contents of the file. But if it doesn't the error message is also printed on the terminal. I expect it to be redirected to the file 'bar'...

The way you have it set up, it's anything that "cat" prints to stderr that goes to the file "bar". My understanding is that because you've used a '<' to read the file, it's bash (rather than "cat") that's reading the file for you, then passing its contents into "cat". As the file doesn't exist, its output is printed to stderr (which is your terminal screen since you haven't redirected it).
Comments on this post
RAJ_55555 agrees: Thanx for your reply

Reply With Quote
  #8  
Old December 1st, 2010, 08:26 AM
RAJ_55555's Avatar
RAJ_55555 RAJ_55555 is offline
Hats off to Mr. Joseph donahue
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2009
Posts: 749 RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 50 m 39 sec
Reputation Power: 1105
@SimonJM
I know that I don't need to redirect stdin into cat. But I was learning to use cat with foo, without informing cat of the existence of the file. Thus the redirection. Thanks :-p

@ishnid
I thought somewhat similar, but wasn't(isn't) exactly clear to me. I understand that bash reads the file foo and if the file doesn't exist, its output goes to stderr.

Now, what you are saying is that the stderr for cat is the file 'bar', but for the shell, its the Terminal. Am I right? I think it makes sense.

Reply With Quote
  #9  
Old December 2nd, 2010, 06:13 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 41 m
Reputation Power: 1485
Yes, that is pretty much it ... each command, process, etc. runs under it's own steam in *nix systems - unless you 'bundle' them together using brackets. Thus your cat < foo 2> bar is, in effect, 2 things - first the 'silent' copying of foo into stdin by the shell, then the cat command processing that input. If the file foo does not exist that is handled by the shell, whereas the redirection of stderr used is aimed at the cat command.
When you used (cat < foo) you bundled the two together so the stderr redirection worked on the error output from both.
Comments on this post
RAJ_55555 agrees: Thanx for the confirmation.

Reply With Quote
  #10  
Old December 2nd, 2010, 07:08 AM
RAJ_55555's Avatar
RAJ_55555 RAJ_55555 is offline
Hats off to Mr. Joseph donahue
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2009
Posts: 749 RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level)RAJ_55555 User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 15 h 50 m 39 sec
Reputation Power: 1105
Thanks a lot both of you. I will be back later with more queries. :-)

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Doesn't get redirected to std error

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap