jQuery in Action, 2nd edition*
The moose likes Linux / UNIX and the fly likes /dev/null not working as expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "/dev/null not working as expected" Watch "/dev/null not working as expected" New topic
Author

/dev/null not working as expected

Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

Hi,

I have a statement like this:



Here if java doesn't exist in the system it throws some output like
no java in (/usr/local/bin:/usr/bin
And I don't want this to be on the console.
So, even after redirecting the output to /dev/null it's still sending the output to the console.
Any idea?



Thanks and Regards,
~Sujoy
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Try something like:
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

Thanks a lot Koen!
Well I modified to my need so that I don't have to write that in every command.



This worked nicely.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

Sujoy Choudhury wrote:
So, even after redirecting the output to /dev/null it's still sending the output to the console.


Unix (Linux) doesn't have a "the output". It has 2 outputs: stdout and stderr. The constructs ">xxxx" and "1>xxxx" redirect stdout to "xxxx", but do not affect stderr. The construct "2>xxxx> redirects stderr to "xxxx" but does not affect stdout. The construct ">& xxxx" redirects both stdout and stderr to "xxxx".

Your problem was that the output was being channelled to stderr when you thought it would be going to stdout.


Customer surveys are for companies who didn't pay proper attention to begin with.
Sujoy Choudhury
Ranch Hand

Joined: Sep 17, 2008
Posts: 136

Thanks a lot Tim!
Nice explanation...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: /dev/null not working as expected
 
Similar Threads
jdk1.3.0_02 PATH????????????
Running JBoss-5.1.0.GA as a service on Red Hat?
How to uninstall / override previous Maven version on OS X Leopard?
why PATH environment is wrong in Java application?
Problem With Algorithm Involving Recursion and String Manipulation