[SOLVED] PING can't redirect errors

SlowCoder

Gold Member
Gold Supporter
Joined
May 2, 2022
Messages
455
Reaction score
316
Credits
3,611
I'm running the following command to retrieve the exit status. I don't actually need/want any of the command output.
Bash:
ping -q -c 1 computer.local 2>&1 > /dev/null
Note the redirect of STDOUT AND STDERR to /dev/null. So I expect not to see anything.

It works fine when the host is pingable. But if the host is not pingable, the error still displays
Code:
ping: computer.local: Name or service not known

I've tried this other variation, to the same effect:
Bash:
ping -q -c 1 computer.local 2 > /dev/null > /dev/null

I'm using LMDE5. Is this happening in other distros, or ping versions?
 


I suspect you are getting a DNS error, not a ping error.
To test this, ping by IP address.

Ping a known good IP address.
Ping a known bad IP address.

I think you won't get output from either case.
Is computer.local in a host file or DNS?
Try putting it in to both a good and bad IP address.

I think you will see it, when it can't look it up.
 
I suspect you are getting a DNS error, not a ping error.
To test this, ping by IP address.
Yeah, it is a DNS error, but I'd expect any output from the current command (ping) to be redirected accordingly.

Interestingly, I tried the following command, and it worked:
Bash:
ping -q -c 1 computer.local &> /dev/null
Supposedly &> and 2>&1 are supposed to be similar/identical. I guess not.
 

Members online


Top